MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / assertFastSwitchover

Function assertFastSwitchover

tests/e2e/fastswitchover_test.go:95–207  ·  view source on GitHub ↗
(namespace, sampleFile, clusterName, webTestFile, webTestJob string)

Source from the content-addressed store, hash-verified

93})
94
95func 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

Callers 1

Calls 12

CreateResourceFromFileFunction · 0.92
FirstEndpointSliceIPFunction · 0.92
RunExecOverForwardFunction · 0.92
RunFunction · 0.92
WaitForReadyFunction · 0.92
QueryInInstancePodFunction · 0.92
GetFunction · 0.92
StatusMethod · 0.80
GetNameMethod · 0.65
GetMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected