(namespace, sampleFile, clusterName, webTestFile, webTestJob string)
| 93 | }) |
| 94 | |
| 95 | func assertFastSwitchover(namespace, sampleFile, clusterName, webTestFile, webTestJob string) { |
| 96 | var oldPrimary, targetPrimary string |
| 97 | |
| 98 | By(fmt.Sprintf("having a %v namespace", namespace), func() { |
| 99 | // Creating a namespace should be quick |
| 100 | timeout := 20 |
| 101 | namespacedName := types.NamespacedName{ |
| 102 | Namespace: namespace, |
| 103 | Name: namespace, |
| 104 | } |
| 105 | |
| 106 | Eventually(func() (string, error) { |
| 107 | namespaceResource := &corev1.Namespace{} |
| 108 | err := env.Client.Get(env.Ctx, namespacedName, namespaceResource) |
| 109 | return namespaceResource.GetName(), err |
| 110 | }, timeout).Should(BeEquivalentTo(namespace)) |
| 111 | }) |
| 112 | By(fmt.Sprintf("creating a Cluster in the %v namespace", namespace), func() { |
| 113 | resources.CreateResourceFromFile(env, namespace, sampleFile) |
| 114 | }) |
| 115 | By("having a Cluster with three instances ready", func() { |
| 116 | clusterasserts.AssertClusterIsReady(env, namespace, clusterName, testTimeouts[timeouts.ClusterIsReady]) |
| 117 | }) |
| 118 | // Node 1 should be the primary, so the -rw service should |
| 119 | // point there. We verify this. |
| 120 | By("having the current primary on node1", func() { |
| 121 | rwServiceName := clusterName + "-rw" |
| 122 | endpointSlice, err := utils.GetEndpointSliceByServiceName(env.Ctx, env.Client, namespace, rwServiceName) |
| 123 | Expect(err).ToNot(HaveOccurred()) |
| 124 | |
| 125 | oldPrimary = clusterName + "-1" |
| 126 | pod := &corev1.Pod{} |
| 127 | err = env.Client.Get(env.Ctx, types.NamespacedName{Namespace: namespace, Name: oldPrimary}, pod) |
| 128 | Expect(err).ToNot(HaveOccurred()) |
| 129 | Expect(utils.FirstEndpointSliceIP(endpointSlice)).To(BeEquivalentTo(pod.Status.PodIP)) |
| 130 | }) |
| 131 | By("preparing the db for the test scenario", func() { |
| 132 | // Create the table used by the scenario |
| 133 | query := "CREATE SCHEMA IF NOT EXISTS tps; " + |
| 134 | "CREATE TABLE IF NOT EXISTS tps.tl ( " + |
| 135 | "id BIGSERIAL" + |
| 136 | ", timeline TEXT DEFAULT (substring(pg_walfile_name(" + |
| 137 | " pg_current_wal_lsn()), 1, 8))" + |
| 138 | ", t timestamp DEFAULT (clock_timestamp() AT TIME ZONE 'UTC')" + |
| 139 | ", source text NOT NULL" + |
| 140 | ", PRIMARY KEY (id)" + |
| 141 | ")" |
| 142 | |
| 143 | _, err := postgres.RunExecOverForward( |
| 144 | env.Ctx, env.Client, env.Interface, env.RestClientConfig, |
| 145 | namespace, clusterName, postgres.AppDBName, |
| 146 | apiv1.ApplicationUserSecretSuffix, query) |
| 147 | Expect(err).ToNot(HaveOccurred()) |
| 148 | }) |
| 149 | |
| 150 | By("starting load", func() { |
| 151 | // We set up Apache Benchmark and webtest. Apache Benchmark, a load generator, |
| 152 | // continuously calls the webtest api to execute inserts |
no test coverage detected