Skip to content

Commit

Permalink
Fix test printing old value for debugging (#2855)
Browse files Browse the repository at this point in the history
* Fix test printing old value for debugging

ShouldNot(Equal(currentVersion), out) is a method call and as such, it
received the value of `out` at the time of the call. That was not the
updated value after the `Eventually` timeout had passed but rather the
value from the previous call that populated it.
This made the test output very confusing because, even though the
upgrade Pod was erroring out, the output shows the cluster being only
some seconds old and the pod still being created (ouch!)

Signed-off-by: Dimitris Karakasilis <[email protected]>

* Remove unecessary args and fix one more case

of passing old value instead of func

Signed-off-by: Dimitris Karakasilis <[email protected]>

---------

Signed-off-by: Dimitris Karakasilis <[email protected]>
  • Loading branch information
jimmykarily authored Sep 13, 2024
1 parent 815c277 commit 7aa3a71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 5 additions & 5 deletions tests/provider_decentralized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("kairos decentralized k8s test", Label("provider", "provider-de
Expect(err).ToNot(HaveOccurred())

out, _ := vm.Sudo("kairos-agent manual-install --device auto /tmp/config.yaml")
Expect(out).Should(ContainSubstring("Running after-install hook"), out)
Expect(out).Should(ContainSubstring("Running after-install hook"))
vm.Reboot()

By("waiting until it reboots to installed system")
Expand Down Expand Up @@ -146,13 +146,13 @@ var _ = Describe("kairos decentralized k8s test", Label("provider", "provider-de
Eventually(func() string {
out, _ = vm.Sudo("kairos get-kubeconfig")
return out
}, 1500*time.Second, 10*time.Second).Should(ContainSubstring("https:"), out)
}, 1500*time.Second, 10*time.Second).Should(ContainSubstring("https:"))

Eventually(func() string {
vm.Sudo("kairos get-kubeconfig > kubeconfig")
out, _ = vm.Sudo("KUBECONFIG=kubeconfig kubectl get nodes -o wide")
return out
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("Ready"), out)
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("Ready"))
})

vmForEach("checking roles", vms, func(vm VM) {
Expand Down Expand Up @@ -195,11 +195,11 @@ var _ = Describe("kairos decentralized k8s test", Label("provider", "provider-de

out, _ = vm.Sudo("dig +short foo.bar")
return strings.TrimSpace(out)
}, 900*time.Second, 10*time.Second).Should(Equal("2.2.2.2"), out)
}, 900*time.Second, 10*time.Second).Should(Equal("2.2.2.2"))
Eventually(func() string {
out, _ = vm.Sudo("dig +short google.com")
return strings.TrimSpace(out)
}, 900*time.Second, 10*time.Second).ShouldNot(BeEmpty(), out)
}, 900*time.Second, 10*time.Second).ShouldNot(BeEmpty())
}
})

Expand Down
8 changes: 5 additions & 3 deletions tests/provider_upgrade_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ var _ = Describe("k3s upgrade test", Label("provider", "provider-upgrade-k8s"),
Eventually(func() string {
out, _ = kubectl(vm, "get pods -A")
return out
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("apply-os-upgrade-on-"), out)
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("apply-os-upgrade-on-"))

By("wait for plan to finish")
Eventually(func() string {
out, _ = kubectl(vm, "get pods -A")
return out
}, 30*time.Minute, 10*time.Second).ShouldNot(ContainSubstring("ContainerCreating"), out)
}, 30*time.Minute, 10*time.Second).ShouldNot(ContainSubstring("ContainerCreating"))

By("validate upgraded version")
expectedVersion := getExpectedVersion()
Expand All @@ -160,7 +160,9 @@ var _ = Describe("k3s upgrade test", Label("provider", "provider-upgrade-k8s"),
version, _ := vm.Sudo(getVersionCmd)
fmt.Printf("version = %+v\n", version)
return version
}, 30*time.Minute, 10*time.Second).Should(ContainSubstring(expectedVersion), out)
}, 30*time.Minute, 10*time.Second).Should(ContainSubstring(expectedVersion), func() string {
return out
})
})
})

Expand Down
13 changes: 10 additions & 3 deletions tests/provider_upgrade_latest_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ var _ = Describe("k3s upgrade test from k8s", Label("provider", "provider-upgrad
Eventually(func() string {
out, _ = kubectl(vm, "apply -f suc.yaml")
return out
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("created"), out)
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("created"))

Eventually(func() string {
out, _ = kubectl(vm, "get pods -A")
return out
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("apply-os-upgrade-on-"), out)
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("apply-os-upgrade-on-"))

By("checking upgraded version")
Eventually(func() string {
Expand All @@ -176,6 +176,13 @@ var _ = Describe("k3s upgrade test from k8s", Label("provider", "provider-upgrad
return currentVersion
}
return version
}, 50*time.Minute, 10*time.Second).ShouldNot(Equal(currentVersion), out)
}, 50*time.Minute, 10*time.Second).ShouldNot(Equal(currentVersion), func() string {
out, _ := kubectl(vm, "get pods -A")
if err != nil {
return fmt.Sprintf("errored while trying to get debug output: %s", err.Error())
} else {
return out
}
})
})
})

0 comments on commit 7aa3a71

Please sign in to comment.