From 29018dd04ceb9e36b372e7594be37725082e7fa8 Mon Sep 17 00:00:00 2001 From: Javier Cano Cano Date: Mon, 29 Jan 2024 13:00:35 +0100 Subject: [PATCH] fix: `Eventually()` missing `Should()` statement The linter enforces the usage of `Should()` statements when a `Eventually` check is used. Also, `DeferCleanup` has been dropped in favor of `defer`. The [`resetToDefaultConfig()` ](https://github.com/kubevirt/kubevirt/blob/cb1b6e53540189d6664c4a8c126ab6e0a84ff8c4/tests/utils.go#L1842) is called before the test `DeferCleanup`, creating the following error: "resource & config versions (5548 and 4736 respectively) are not as expected. component: \"virt-handler\", pod: \"virt-handler-zdv7f\" " This is because the `virt-handler` will not be ready (intentionally for the purposes of the test), and the `resetToDefaultConfig()` will force the `virt-handler` to reconcile, which will fail, but the `virt-handler` `resourceVersion` will be updated. Therefore, the Kubevirt object will be out of sync. Signed-off-by: Javier Cano Cano --- tests/vm_test.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/vm_test.go b/tests/vm_test.go index 947b55cfe5d8..056c54c1a203 100644 --- a/tests/vm_test.go +++ b/tests/vm_test.go @@ -1969,12 +1969,25 @@ status: By("Blocking virt-handler from reconciling the VMI") libpod.AddKubernetesApiBlackhole(getHandlerNodePod(virtClient, nodeName), componentName) - Eventually(getHandlerNodePod(virtClient, nodeName).Items[0], 120*time.Second, time.Second, HaveConditionFalse(k8sv1.PodReady)) + Eventually(func() k8sv1.Pod { + return getHandlerNodePod(virtClient, nodeName).Items[0] + }, 120*time.Second, time.Second).Should(HaveConditionFalse(k8sv1.PodReady)) - DeferCleanup(func() { + defer func() { libpod.DeleteKubernetesApiBlackhole(getHandlerNodePod(virtClient, nodeName), componentName) - Eventually(getHandlerNodePod(virtClient, nodeName).Items[0], 120*time.Second, time.Second, HaveConditionTrue(k8sv1.PodReady)) - }) + Eventually(func() k8sv1.Pod { + return getHandlerNodePod(virtClient, nodeName).Items[0] + }, 120*time.Second, time.Second).Should(HaveConditionTrue(k8sv1.PodReady)) + + // FIXME: this is just a test to see if the flakiness is reduced + migrationBandwidth := resource.MustParse("1Mi") + kv := util.GetCurrentKv(virtClient) + kv.Spec.Configuration.MigrationConfiguration = &v1.MigrationConfiguration{ + BandwidthPerMigration: &migrationBandwidth, + } + kv = testsuite.UpdateKubeVirtConfigValue(kv.Spec.Configuration) + tests.WaitForConfigToBePropagatedToComponent("kubevirt.io=virt-handler", kv.ResourceVersion, tests.ExpectResourceVersionToBeLessEqualThanConfigVersion, 120*time.Second) + }() pod, err := libvmi.GetPodByVirtualMachineInstance(vmi, vmi.Namespace) Expect(err).ToNot(HaveOccurred())