From 397745f71568b95175ae41afcb2eb0b684bde7b7 Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Wed, 10 May 2023 12:03:47 +0200 Subject: [PATCH] Add test highlighting the issue and setting the expectations --- tests/helper/helper_filesystem.go | 9 +++++++- tests/integration/cmd_dev_test.go | 37 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/helper/helper_filesystem.go b/tests/helper/helper_filesystem.go index 55a9a339718..d76f7edc583 100644 --- a/tests/helper/helper_filesystem.go +++ b/tests/helper/helper_filesystem.go @@ -238,8 +238,15 @@ func copyDir(src string, dst string, info os.FileInfo) error { // path is the path to the required file // fileContent is the content to be written to the given file func CreateFileWithContent(path string, fileContent string) error { + return CreateFileWithContentAndPerm(path, fileContent, 0600) +} + +// CreateFileWithContentAndPerm creates a file at the given path using the given file permissions, and writes the given content. +// path is the path to the required file +// fileContent is the content to be written to the given file +func CreateFileWithContentAndPerm(path string, fileContent string, perm os.FileMode) error { // create and open file if not exists - var file, err = os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600) + var file, err = os.OpenFile(path, os.O_RDWR|os.O_CREATE, perm) if err != nil { return err } diff --git a/tests/integration/cmd_dev_test.go b/tests/integration/cmd_dev_test.go index 682b93ef8a2..0092e3082d6 100644 --- a/tests/integration/cmd_dev_test.go +++ b/tests/integration/cmd_dev_test.go @@ -3,8 +3,10 @@ package integration import ( "bufio" "encoding/json" + "errors" "fmt" "io" + "io/fs" "net/http" "net/http/httptest" "os" @@ -80,6 +82,41 @@ var _ = Describe("odo dev command tests", func() { errOut := helper.Cmd("odo", "dev", "--platform", "podman").WithEnv("PODMAN_CMD=echo").ShouldFail().Err() Expect(errOut).To(ContainSubstring("unable to access podman")) }) + + It("should start on cluster even if Podman client takes long to initialize", func() { + if runtime.GOOS == "windows" { + Skip("skipped on Windows as it requires Unix permissions") + } + _, err := os.Stat("/bin/bash") + if errors.Is(err, fs.ErrNotExist) { + Skip("skipped because bash executable not found") + } + + // odo dev on cluster should not wait for the Podman client to initialize properly, if this client takes very long. + // See https://github.com/redhat-developer/odo/issues/6575. + // StartDevMode will time out if Podman client takes too long to initialize. + delayer := filepath.Join(commonVar.Context, "podman-cmd-delayer") + err = helper.CreateFileWithContentAndPerm(delayer, `#!/bin/bash + +echo Delaying command execution... >&2 +sleep 7200 +echo "$@" +`, 0755) + Expect(err).ShouldNot(HaveOccurred()) + + var devSession helper.DevSession + var stderrBytes []byte + devSession, _, stderrBytes, _, err = helper.StartDevMode(helper.DevSessionOpts{ + RunOnPodman: false, + CmdlineArgs: []string{"-v", "3"}, + EnvVars: []string{"PODMAN_CMD=" + delayer}, + }) + Expect(err).ShouldNot(HaveOccurred()) + defer devSession.Kill() + + Expect(string(stderrBytes)).Should(ContainSubstring("timeout while waiting for Podman version")) + }) + When("using a default namespace", func() { BeforeEach(func() { commonVar.CliRunner.SetProject("default")