Skip to content

Commit

Permalink
chore(e2e): Dev mode flaky test rendomize name
Browse files Browse the repository at this point in the history
  • Loading branch information
gansheer authored and squakez committed Nov 20, 2023
1 parent 0c6e0e0 commit 2089fc2
Showing 1 changed file with 22 additions and 19 deletions.
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

0 comments on commit 2089fc2

Please sign in to comment.