Skip to content

Commit

Permalink
fix: Eventually() missing Should() statement
Browse files Browse the repository at this point in the history
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 <jcanocan@redhat.com>
  • Loading branch information
jcanocan committed Jan 29, 2024
1 parent a6f4f91 commit 29018dd
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tests/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 29018dd

Please sign in to comment.