Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(e2e): Dev mode flaky test randomize name #4921

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions e2e/common/cli/dev_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,25 @@ func TestRunDevMode(t *testing.T) {
defer piper.Close()

file := util.MakeTempCopy(t, "files/yaml.yaml")
name := RandomizedSuffixName("yaml")

kamelRun := KamelRunWithContext(ctx, operatorID, ns, file, "--dev")
kamelRun := KamelRunWithContext(ctx, operatorID, ns, file, "--name", name, "--dev")
kamelRun.SetOut(pipew)

logScanner := util.NewLogScanner(ctx, piper, `integration "yaml" in phase Running`, "Magicstring!", "Magicjordan!")
logScanner := util.NewLogScanner(ctx, piper, `integration "`+name+`" in phase Running`, "Magicstring!", "Magicjordan!")

args := os.Args
defer func() { os.Args = args }()

globalTest := os.Getenv("CAMEL_K_FORCE_GLOBAL_TEST") == "true"
if globalTest {
os.Args = []string{"kamel", "run", "-n", ns, file, "--dev"}
os.Args = []string{"kamel", "run", "-n", ns, file, "--name", name, "--dev"}
} else {
os.Args = []string{"kamel", "run", "-n", ns, "--operator-id", operatorID, file, "--dev"}
os.Args = []string{"kamel", "run", "-n", ns, "--operator-id", operatorID, file, "--name", name, "--dev"}
}
go kamelRun.Execute()

Eventually(logScanner.IsFound(`integration "yaml" in phase Running`), TestTimeoutMedium).Should(BeTrue())
Eventually(logScanner.IsFound(`integration "`+name+`" in phase Running`), TestTimeoutMedium).Should(BeTrue())
Eventually(logScanner.IsFound("Magicstring!"), TestTimeoutMedium).Should(BeTrue())
Expect(logScanner.IsFound("Magicjordan!")()).To(BeFalse())

Expand All @@ -93,7 +94,8 @@ func TestRunDevMode(t *testing.T) {
defer piper.Close()

remoteFile := "https://raw.githubusercontent.com/apache/camel-k/b29333f0a878d5d09fb3965be8fe586d77dd95d0/e2e/common/files/yaml.yaml"
kamelRun := KamelRunWithContext(ctx, operatorID, ns, remoteFile, "--dev")
name := RandomizedSuffixName("yaml")
kamelRun := KamelRunWithContext(ctx, operatorID, ns, remoteFile, "--name", name, "--dev")
kamelRun.SetOut(pipew)

logScanner := util.NewLogScanner(ctx, piper, "Magicstring!")
Expand All @@ -103,9 +105,9 @@ func TestRunDevMode(t *testing.T) {

globalTest := os.Getenv("CAMEL_K_FORCE_GLOBAL_TEST") == "true"
if globalTest {
os.Args = []string{"kamel", "run", "-n", ns, remoteFile, "--dev"}
os.Args = []string{"kamel", "run", "-n", ns, remoteFile, "--name", name, "--dev"}
} else {
os.Args = []string{"kamel", "run", "-n", ns, "--operator-id", operatorID, remoteFile, "--dev"}
os.Args = []string{"kamel", "run", "-n", ns, "--operator-id", operatorID, remoteFile, "--name", name, "--dev"}
}

go kamelRun.Execute()
Expand All @@ -123,14 +125,15 @@ func TestRunDevMode(t *testing.T) {
* the integration startup.
*/
RegisterTestingT(t)
name := RandomizedSuffixName("yaml")

// First run (warm up)
Expect(KamelRunWithID(operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
Expect(Kamel("delete", "yaml", "-n", ns).Execute()).To(Succeed())
Eventually(Integration(ns, "yaml")).Should(BeNil())
Eventually(IntegrationPod(ns, "yaml"), TestTimeoutMedium).Should(BeNil())
Expect(KamelRunWithID(operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed())
Eventually(Integration(ns, name)).Should(BeNil())
Eventually(IntegrationPod(ns, name), TestTimeoutMedium).Should(BeNil())

// Second run (rebuild)
ctx, cancel := context.WithCancel(TestContext)
Expand All @@ -141,26 +144,26 @@ func TestRunDevMode(t *testing.T) {

file := util.MakeTempCopy(t, "files/yaml.yaml")

kamelRun := KamelRunWithContext(ctx, operatorID, ns, file, "--dev")
kamelRun := KamelRunWithContext(ctx, operatorID, ns, file, "--name", name, "--dev")
kamelRun.SetOut(pipew)

logScanner := util.NewLogScanner(ctx, piper, `integration "yaml" in phase Running`, "Magicstring!")
logScanner := util.NewLogScanner(ctx, piper, `integration "`+name+`" in phase Running`, "Magicstring!")

args := os.Args
defer func() { os.Args = args }()

globalTest := os.Getenv("CAMEL_K_FORCE_GLOBAL_TEST") == "true"
if globalTest {
os.Args = []string{"kamel", "run", "-n", ns, file, "--dev"}
os.Args = []string{"kamel", "run", "-n", ns, file, "--name", name, "--dev"}
} else {
os.Args = []string{"kamel", "run", "-n", ns, "--operator-id", operatorID, file, "--dev"}
os.Args = []string{"kamel", "run", "-n", ns, "--operator-id", operatorID, file, "--name", name, "--dev"}
}

go kamelRun.Execute()

// Second run should start up within a few seconds
timeout := 10 * time.Second
Eventually(logScanner.IsFound(`integration "yaml" in phase Running`), timeout).Should(BeTrue())
Eventually(logScanner.IsFound(`integration "`+name+`" in phase Running`), timeout).Should(BeTrue())
Eventually(logScanner.IsFound("Magicstring!"), timeout).Should(BeTrue())
})

Expand Down
Loading