From dbb227e4c92a9b05155e82e66aaf371674903111 Mon Sep 17 00:00:00 2001 From: Russell Centanni Date: Fri, 12 Jan 2024 14:42:47 -0500 Subject: [PATCH] test: add lock around executing helm binary Signed-off-by: Russell Centanni --- e2e/tests/ssh/framework.go | 2 +- e2e/tests/ssh/ssh.go | 44 ++++++++++++++----- .../ssh/testdata/ssh-simple/devspace.yaml | 4 ++ .../ssh/testdata/ssh-variable/devspace.yaml | 4 ++ .../loader/variable/predefined_variable.go | 2 +- pkg/devspace/helm/generic/generic.go | 9 ++-- 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/e2e/tests/ssh/framework.go b/e2e/tests/ssh/framework.go index 8a656cce58..f20a265a70 100644 --- a/e2e/tests/ssh/framework.go +++ b/e2e/tests/ssh/framework.go @@ -4,5 +4,5 @@ import "github.com/onsi/ginkgo/v2" // DevSpaceDescribe annotates the test with the label. func DevSpaceDescribe(text string, body func()) bool { - return ginkgo.Describe("[ssh] "+text, body) + return ginkgo.FDescribe("[ssh] "+text, body) } diff --git a/e2e/tests/ssh/ssh.go b/e2e/tests/ssh/ssh.go index afb7cffded..0dac3af0f3 100644 --- a/e2e/tests/ssh/ssh.go +++ b/e2e/tests/ssh/ssh.go @@ -45,7 +45,7 @@ var _ = DevSpaceDescribe("ssh", func() { // create a new dev command and start it done := make(chan error) - cancelCtx, cancel := context.WithCancel(context.Background()) + cancelCtx, cancel := context.WithCancel(ctx) ginkgo.DeferCleanup(cancel) go func() { @@ -63,23 +63,31 @@ var _ = DevSpaceDescribe("ssh", func() { done <- devCmd.RunDefault(f) }() + // Wait for the dev session to start + gomega.Eventually(func(g gomega.Gomega) { + _, err := os.ReadFile("started") + g.Expect(err).NotTo(gomega.HaveOccurred()) + }). + WithPolling(time.Second). + WithTimeout(time.Second * 60). + Should(gomega.Succeed()) + // connect to the SSH server gomega.Eventually(func(g gomega.Gomega) { cmd := exec.Command("ssh", "test.ssh-simple.devspace", "ls") err := cmd.Run() g.Expect(err).NotTo(gomega.HaveOccurred()) - - cancel() }). WithPolling(time.Second). WithTimeout(time.Second * 60). Should(gomega.Succeed()) + cancel() err = <-done framework.ExpectNoError(err) }) - ginkgo.It("devspace dev should NOT start an SSH service when disabled with a variable", ginkgo.FlakeAttempts(3), func(ctx context.Context) { + ginkgo.It("devspace dev should NOT start an SSH service when disabled with a variable", func(ctx context.Context) { tempDir, err := framework.CopyToTempDir("tests/ssh/testdata/ssh-variable") framework.ExpectNoError(err) ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tempDir) @@ -90,7 +98,7 @@ var _ = DevSpaceDescribe("ssh", func() { // create a new dev command and start it done := make(chan error) - cancelCtx, cancel := context.WithCancel(context.Background()) + cancelCtx, cancel := context.WithCancel(ctx) ginkgo.DeferCleanup(cancel) go func() { @@ -110,6 +118,15 @@ var _ = DevSpaceDescribe("ssh", func() { done <- devCmd.RunDefault(f) }() + // Wait for the dev session to start + gomega.Eventually(func(g gomega.Gomega) { + _, err := os.ReadFile("started") + g.Expect(err).NotTo(gomega.HaveOccurred()) + }). + WithPolling(time.Second). + WithTimeout(time.Second * 60). + Should(gomega.Succeed()) + gomega.Eventually(func(g gomega.Gomega) { cmd := exec.Command("ssh", "test.ssh-variable.devspace", "ls") out, err := cmd.CombinedOutput() @@ -121,13 +138,12 @@ var _ = DevSpaceDescribe("ssh", func() { gomega.ContainSubstring("ssh: connect to host localhost port 10023"), ), ) - - cancel() }). WithPolling(time.Second). WithTimeout(time.Second * 60). Should(gomega.Succeed()) + cancel() cmdErr := <-done framework.ExpectNoError(cmdErr) }) @@ -143,7 +159,7 @@ var _ = DevSpaceDescribe("ssh", func() { // create a new dev command and start it done := make(chan error) - cancelCtx, cancel := context.WithCancel(context.Background()) + cancelCtx, cancel := context.WithCancel(ctx) ginkgo.DeferCleanup(cancel) go func() { @@ -163,18 +179,26 @@ var _ = DevSpaceDescribe("ssh", func() { done <- devCmd.RunDefault(f) }() + // Wait for the dev session to start + gomega.Eventually(func(g gomega.Gomega) { + _, err := os.ReadFile("started") + g.Expect(err).NotTo(gomega.HaveOccurred()) + }). + WithPolling(time.Second). + WithTimeout(time.Second * 60). + Should(gomega.Succeed()) + // connect to the SSH server gomega.Eventually(func(g gomega.Gomega) { cmd := exec.Command("ssh", "test.ssh-variable.devspace", "ls") err := cmd.Run() g.Expect(err).NotTo(gomega.HaveOccurred()) - - cancel() }). WithPolling(time.Second). WithTimeout(time.Second * 60). Should(gomega.Succeed()) + cancel() cmdErr := <-done framework.ExpectNoError(cmdErr) }) diff --git a/e2e/tests/ssh/testdata/ssh-simple/devspace.yaml b/e2e/tests/ssh/testdata/ssh-simple/devspace.yaml index 1654dd5af7..64861aa2c0 100644 --- a/e2e/tests/ssh/testdata/ssh-simple/devspace.yaml +++ b/e2e/tests/ssh/testdata/ssh-simple/devspace.yaml @@ -13,6 +13,10 @@ deployments: - image: ${IMAGE} command: ["sleep"] args: ["999999999999"] +pipelines: + dev: | + run_default_pipeline dev + echo "started" > started dev: test: imageSelector: ${IMAGE} diff --git a/e2e/tests/ssh/testdata/ssh-variable/devspace.yaml b/e2e/tests/ssh/testdata/ssh-variable/devspace.yaml index 11a6846e18..fd8d627fab 100644 --- a/e2e/tests/ssh/testdata/ssh-variable/devspace.yaml +++ b/e2e/tests/ssh/testdata/ssh-variable/devspace.yaml @@ -15,6 +15,10 @@ deployments: - image: ${IMAGE} command: ["sleep"] args: ["999999999999"] +pipelines: + dev: | + run_default_pipeline dev + echo "started" > started dev: test: imageSelector: ${IMAGE} diff --git a/pkg/devspace/config/loader/variable/predefined_variable.go b/pkg/devspace/config/loader/variable/predefined_variable.go index ddeccc027d..d8e2fb6d24 100644 --- a/pkg/devspace/config/loader/variable/predefined_variable.go +++ b/pkg/devspace/config/loader/variable/predefined_variable.go @@ -6,13 +6,13 @@ import ( "encoding/json" "errors" "fmt" - "github.com/loft-sh/devspace/pkg/devspace/config/constants" "os" "path/filepath" "strconv" "strings" "time" + "github.com/loft-sh/devspace/pkg/devspace/config/constants" "github.com/loft-sh/devspace/pkg/devspace/context/values" "github.com/loft-sh/devspace/pkg/devspace/kubectl" "github.com/loft-sh/devspace/pkg/util/log" diff --git a/pkg/devspace/helm/generic/generic.go b/pkg/devspace/helm/generic/generic.go index 65b6f66cc8..9ae560bac1 100644 --- a/pkg/devspace/helm/generic/generic.go +++ b/pkg/devspace/helm/generic/generic.go @@ -7,18 +7,15 @@ import ( "strings" "github.com/loft-sh/devspace/pkg/devspace/config/constants" - devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context" - "github.com/loft-sh/utils/pkg/command" - - "gopkg.in/yaml.v3" - "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest" + devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context" "github.com/loft-sh/devspace/pkg/util/log" + "github.com/loft-sh/utils/pkg/command" "github.com/loft-sh/utils/pkg/downloader" "github.com/loft-sh/utils/pkg/downloader/commands" "github.com/loft-sh/utils/pkg/extract" - "github.com/pkg/errors" + "gopkg.in/yaml.v3" ) const stableChartRepo = "https://charts.helm.sh/stable"