Skip to content

Commit

Permalink
chore: fix flaky tests (#623)
Browse files Browse the repository at this point in the history
Issue #, if available:

*Description of changes:*

*Testing done:*



- [ ] I've reviewed the guidance in CONTRIBUTING.md


#### License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

Signed-off-by: Vishwas Siravara <[email protected]>
Co-authored-by: Vishwas Siravara <[email protected]>
  • Loading branch information
vsiravar and Vishwas Siravara authored Oct 12, 2023
1 parent 8990eb6 commit 235327c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
14 changes: 10 additions & 4 deletions e2e/vm/additional_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vm

import (
"fmt"
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand All @@ -19,23 +20,28 @@ const (
networkName = "test-network"
)

var testAdditionalDisk = func(o *option.Option) {
var testAdditionalDisk = func(o *option.Option, installed bool) {
ginkgo.Describe("Additional disk", ginkgo.Serial, func() {
ginkgo.It("Retains container user data after the VM is deleted", func() {
resetVM(o, installed)
resetDisks(o, installed)
command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
command.Run(o, "volume", "create", volumeName)
ginkgo.DeferCleanup(command.Run, o, "volume", "rm", volumeName)
command.Run(o, "network", "create", networkName)
ginkgo.DeferCleanup(command.Run, o, "network", "rm", networkName)

command.Run(o, "run", "-d", "--name", containerName, "-v", fmt.Sprintf("%s:/tmp", volumeName),
savedImage, "sh", "-c", "sleep infinity")
savedImage, "sleep", "infinity")
command.Run(o, "exec", containerName, "sh", "-c", "echo foo > /tmp/test.txt")
ginkgo.DeferCleanup(command.Run, o, "rmi", savedImage)
ginkgo.DeferCleanup(command.Run, o, "rm", "-f", containerName)

command.Run(o, "kill", containerName)
command.New(o, "stop", containerName).WithTimeoutInSeconds(30).Run()

command.New(o, virtualMachineRootCmd, "stop").WithoutCheckingExitCode().WithTimeoutInSeconds(90).Run()
time.Sleep(20 * time.Second)

command.New(o, virtualMachineRootCmd, "stop").WithTimeoutInSeconds(90).Run()
command.Run(o, virtualMachineRootCmd, "remove")
command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(240).Run()

Expand Down
2 changes: 2 additions & 0 deletions e2e/vm/config_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/runfinch/finch/pkg/config"
)

var finchConfigFilePath string = os.Getenv("HOME") + "/.finch/finch.yaml"

var testConfig = func(o *option.Option, installed bool) {
ginkgo.Describe("Config (after init)", ginkgo.Serial, func() {
ginkgo.It("updates init-only config values when values are changed after init", func() {
Expand Down
2 changes: 0 additions & 2 deletions e2e/vm/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/runfinch/finch/e2e"
)

var finchConfigFilePath = os.Getenv("HOME") + "/.finch/finch.yaml"

const defaultLimaConfigFilePath = "../../_output/lima/data/_config/override.yaml"

func readFile(filePath string) []byte {
Expand Down
1 change: 1 addition & 0 deletions e2e/vm/finch_config_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var testFinchConfigFile = func(o *option.Option) {
for command.StdoutStr(o, "inspect", "-f", "{{.State.Running}}", containerID) != "true" {
time.Sleep(1 * time.Second)
}
time.Sleep(10 * time.Second)
registry := fmt.Sprintf(`localhost:%d`, port)
command.Run(o, "login", registry, "-u", "testUser", "-p", "testPassword")

Expand Down
2 changes: 1 addition & 1 deletion e2e/vm/vm_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestVM(t *testing.T) {

ginkgo.Describe("", func() {
testVMLifecycle(o)
testAdditionalDisk(o)
testAdditionalDisk(o, *e2e.Installed)
testConfig(o, *e2e.Installed)
testFinchConfigFile(o)
testVersion(o)
Expand Down
17 changes: 13 additions & 4 deletions e2e/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package vm
import (
"os/exec"
"path/filepath"
"runtime"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -33,14 +34,22 @@ var resetVM = func(o *option.Option, installed bool) string {
}
origLimaCfg := readFile(limaConfigFilePath)

command.New(o, virtualMachineRootCmd, "stop", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(90).Run()
command.New(o, virtualMachineRootCmd, "remove", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(90).Run()
command.New(o, virtualMachineRootCmd, "stop").WithTimeoutInSeconds(120).Run()
command.New(o, virtualMachineRootCmd, "remove").WithTimeoutInSeconds(90).Run()
if runtime.GOOS == "windows" {
// clean up iptables
// https://docs.rancherdesktop.io/troubleshooting-tips/#q-how-do-i-fix-fata0005-subnet-1040024-overlaps-with-other-one-on-this-address-space-when-running-a-container-using-nerdctl-run
gomega.Expect(exec.Command("wsl", "--shutdown").Run()).Should(gomega.BeNil())
}

ginkgo.DeferCleanup(func() {
writeFile(finchConfigFilePath, origFinchCfg)
writeFile(limaConfigFilePath, origLimaCfg)
command.New(o, virtualMachineRootCmd, "stop", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(90).Run()
command.New(o, virtualMachineRootCmd, "remove", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(90).Run()
command.New(o, virtualMachineRootCmd, "stop").WithTimeoutInSeconds(180).Run()
command.New(o, virtualMachineRootCmd, "remove").WithTimeoutInSeconds(180).Run()
if runtime.GOOS == "windows" {
gomega.Expect(exec.Command("wsl", "--shutdown").Run()).Should(gomega.BeNil())
}
command.New(o, virtualMachineRootCmd, "init").WithoutCheckingExitCode().WithTimeoutInSeconds(600).Run()
})

Expand Down
2 changes: 1 addition & 1 deletion e2e/vm/vm_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestVM(t *testing.T) {

ginkgo.Describe("", func() {
testVMLifecycle(o)
testAdditionalDisk(o)
testAdditionalDisk(o, *e2e.Installed)
testFinchConfigFile(o)
testVersion(o)
testSupportBundle(o)
Expand Down

0 comments on commit 235327c

Please sign in to comment.