Skip to content

Commit

Permalink
Merge pull request kubevirt#9331 from kubevirt-bot/cherry-pick-9310-t…
Browse files Browse the repository at this point in the history
…o-release-0.59

[release-0.59] [e2e] Fine-tuning of the pausing test
  • Loading branch information
kubevirt-bot authored Mar 1, 2023
2 parents 8c99a6b + 938f82d commit 78f5184
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/pausing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package tests_test

import (
"context"
"fmt"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -419,6 +420,11 @@ var _ = Describe("[rfe_id:3064][crit:medium][vendor:[email protected]][level:com

Context("Guest and Host uptime difference before pause", func() {
startTime := time.Now()
const (
sleepTimeSeconds = 10
deviation = 4
)

var (
vmi *v1.VirtualMachineInstance
uptimeDiffBeforePausing float64
Expand Down Expand Up @@ -456,7 +462,7 @@ var _ = Describe("[rfe_id:3064][crit:medium][vendor:[email protected]][level:com
command := clientcmd.NewRepeatableVirtctlCommand("pause", "vmi", "--namespace", vmi.Namespace, vmi.Name)
Expect(command()).To(Succeed(), "should successfully pause the vmi")
Eventually(matcher.ThisVMI(vmi), 30*time.Second, time.Second).Should(matcher.HaveConditionTrue(v1.VirtualMachineInstancePaused))
time.Sleep(10 * time.Second) // sleep to increase uptime diff
time.Sleep(sleepTimeSeconds * time.Second) // sleep to increase uptime diff

By("Unpausing the VMI")
command = clientcmd.NewRepeatableVirtctlCommand("unpause", "vmi", "--namespace", vmi.Namespace, vmi.Name)
Expand All @@ -465,7 +471,13 @@ var _ = Describe("[rfe_id:3064][crit:medium][vendor:[email protected]][level:com

By("Verifying VMI was indeed Paused")
uptimeDiffAfterPausing := hostUptime() - grepGuestUptime(vmi)
Expect(uptimeDiffAfterPausing).To(BeNumerically(">", uptimeDiffBeforePausing+10), "uptime diff after pausing should be greater by at least 10 than before pausing")

// We subtract from the sleep time the deviation due to the low resolution of `uptime` (seconds).
// If you capture the uptime when it is at the beginning of that second or at the end of that second,
// the value comes out the same even though in fact a whole second has almost passed.
// In extreme cases, as we take 4 readings (2 initially and 2 after the unpause), the deviation could be up to just under 4 seconds.
// This fact does not invalidate the purpose of the test, which is to prove that during the pause the vmi is actually paused.
Expect(uptimeDiffAfterPausing-uptimeDiffBeforePausing).To(BeNumerically(">=", sleepTimeSeconds-deviation), fmt.Sprintf("guest should be paused for at least %d seconds", sleepTimeSeconds-deviation))
})
})
})

0 comments on commit 78f5184

Please sign in to comment.