Skip to content

Commit

Permalink
ci: add debug code for test vm lockup on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Vazquez <[email protected]>
  • Loading branch information
austinvazquez committed Jun 21, 2024
1 parent 9c1caf0 commit bc59409
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions e2e/vm/vm_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ var resetDisks = func(_ *option.Option, installed bool) {
}
gomega.Expect(os.RemoveAll(dataDiskDir)).ShouldNot(gomega.HaveOccurred())
}

var shutdownWSL = func() error {
// no-op on darwin
return nil
}
5 changes: 2 additions & 3 deletions e2e/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package vm

import (
"os/exec"
"runtime"
"time"

Expand All @@ -29,7 +28,7 @@ var resetVM = func(o *option.Option) {
// clean up iptables
//nolint:lll // link to explanation
// 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())
gomega.Expect(shutdownWSL()).Should(gomega.BeNil())
}

ginkgo.DeferCleanup(func() {
Expand All @@ -38,7 +37,7 @@ var resetVM = func(o *option.Option) {
time.Sleep(1 * time.Second)
command.New(o, virtualMachineRootCmd, "remove", "-f").WithoutCheckingExitCode().WithTimeoutInSeconds(10).Run()
if runtime.GOOS == "windows" {
gomega.Expect(exec.Command("wsl", "--shutdown").Run()).Should(gomega.BeNil())
gomega.Expect(shutdownWSL()).Should(gomega.BeNil())
}
time.Sleep(1 * time.Second)
command.New(o, virtualMachineRootCmd, "init").WithoutCheckingExitCode().WithTimeoutInSeconds(160).Run()
Expand Down
35 changes: 35 additions & 0 deletions e2e/vm/vm_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
package vm

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -60,3 +64,34 @@ var resetDisks = func(_ *option.Option, _ bool) {
dataDiskDir := filepath.Join(finchRootDir, ".finch", ".disks")
gomega.Expect(os.RemoveAll(dataDiskDir)).ShouldNot(gomega.HaveOccurred())
}

// shutdownWSL is a wrapper function for "wsl --shutdown" to only block for 15 seconds
// before failing.
var shutdownWSL = func() error {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()

shutdownCommand := exec.CommandContext(ctx, "wsl", "--user", "root", "--shutdown")
shutdownCommand.Stdout = ginkgo.GinkgoWriter
shutdownCommand.Stderr = ginkgo.GinkgoWriter

if err := shutdownCommand.Run(); err != nil {
fmt.Fprintf(ginkgo.GinkgoWriter, "err(wsl --user root --shutdown): %v", err)

// Failed due to shutdown command not returning in time. Gather extra information.
additionalCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

lsCommand := exec.CommandContext(additionalCtx, "wsl", "--user", "root", "--list", "--verbose")
lsCommand.Stdout = ginkgo.GinkgoWriter
lsCommand.Stderr = ginkgo.GinkgoWriter

if innerErr := lsCommand.Run(); innerErr != nil {
fmt.Fprintf(ginkgo.GinkgoWriter, "err(wsl --user root --list --verbose): %v", innerErr)
}

return err
}

return nil
}

0 comments on commit bc59409

Please sign in to comment.