Skip to content

Commit

Permalink
test: add lock around executing helm binary
Browse files Browse the repository at this point in the history
Signed-off-by: Russell Centanni <russell.centanni@gmail.com>
  • Loading branch information
lizardruss committed Jan 12, 2024
1 parent 26edf30 commit dbb227e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion e2e/tests/ssh/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
44 changes: 34 additions & 10 deletions e2e/tests/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -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() {
Expand All @@ -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()
Expand All @@ -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)
})
Expand All @@ -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() {
Expand All @@ -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)
})
Expand Down
4 changes: 4 additions & 0 deletions e2e/tests/ssh/testdata/ssh-simple/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ deployments:
- image: ${IMAGE}
command: ["sleep"]
args: ["999999999999"]
pipelines:
dev: |
run_default_pipeline dev
echo "started" > started
dev:
test:
imageSelector: ${IMAGE}
Expand Down
4 changes: 4 additions & 0 deletions e2e/tests/ssh/testdata/ssh-variable/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ deployments:
- image: ${IMAGE}
command: ["sleep"]
args: ["999999999999"]
pipelines:
dev: |
run_default_pipeline dev
echo "started" > started
dev:
test:
imageSelector: ${IMAGE}
Expand Down
2 changes: 1 addition & 1 deletion pkg/devspace/config/loader/variable/predefined_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions pkg/devspace/helm/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dbb227e

Please sign in to comment.