squakez commented on code in PR #4330:
URL: https://github.com/apache/camel-k/pull/4330#discussion_r1186168101


##########
e2e/builder/build_test.go:
##########
@@ -57,76 +58,86 @@ func TestKitMaxBuildLimit(t *testing.T) {
                buildB := "integration-b"
                buildC := "integration-c"
 
-               ns1 := NewTestNamespace(false).GetName()
-               defer DumpNamespace(t, ns1)
-               defer DeleteNamespace(t, ns1)
-
-               pl1 := v1.NewIntegrationPlatform(ns1, fmt.Sprintf("camel-k-%s", 
ns))
-               pl.Spec.DeepCopyInto(&pl1.Spec)
-               pl1.Spec.Build.Maven.Settings = v1.ValueSource{}
-               pl1.SetOperatorID(fmt.Sprintf("camel-k-%s", ns))
-               if err := TestClient().Create(TestContext, &pl1); err != nil {
-                       t.Error(err)
-                       t.FailNow()
-               }
-
-               Eventually(PlatformPhase(ns1), 
TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
-
-               ns2 := NewTestNamespace(false).GetName()
-               defer DumpNamespace(t, ns2)
-               defer DeleteNamespace(t, ns2)
-
-               pl2 := v1.NewIntegrationPlatform(ns2, fmt.Sprintf("camel-k-%s", 
ns))
-               pl.Spec.DeepCopyInto(&pl2.Spec)
-               pl2.Spec.Build.Maven.Settings = v1.ValueSource{}
-               pl2.SetOperatorID(fmt.Sprintf("camel-k-%s", ns))
-               if err := TestClient().Create(TestContext, &pl2); err != nil {
-                       t.Error(err)
-                       t.FailNow()
-               }
-
-               Eventually(PlatformPhase(ns2), 
TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
-
-               doKitBuildInNamespace(buildA, ns, TestTimeoutShort, kitOptions{
-                       operatorID: fmt.Sprintf("camel-k-%s", ns),
-                       dependencies: []string{
-                               "camel:timer", "camel:log",
-                       },
-                       traits: []string{
-                               "builder.properties=build-property=A",
-                       },
-               }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning)
-
-               doKitBuildInNamespace(buildB, ns1, TestTimeoutShort, kitOptions{
-                       operatorID: fmt.Sprintf("camel-k-%s", ns),
-                       dependencies: []string{
-                               "camel:timer", "camel:log",
-                       },
-                       traits: []string{
-                               "builder.properties=build-property=B",
-                       },
-               }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning)
-
-               doKitBuildInNamespace(buildC, ns2, TestTimeoutShort, kitOptions{
-                       operatorID: fmt.Sprintf("camel-k-%s", ns),
-                       dependencies: []string{
-                               "camel:timer", "camel:log",
-                       },
-                       traits: []string{
-                               "builder.properties=build-property=C",
-                       },
-               }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone)
-
-               // verify that buildC is allowed to build as soon as buildA has 
finished
-               Eventually(BuildPhase(ns, buildA), 
TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded))
-               Eventually(BuildPhase(ns2, buildC), 
TestTimeoutShort).Should(Equal(v1.BuildPhaseRunning))
-               Eventually(KitPhase(ns2, buildC), 
TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseBuildRunning))
-
-               // verify that all builds are successful
-               Eventually(BuildPhase(ns1, buildB), 
TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded))
-               Eventually(KitPhase(ns1, buildB), 
TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady))
-               Eventually(BuildPhase(ns2, buildC), 
TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded))
-               Eventually(KitPhase(ns2, buildC), 
TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady))
+               WithNewTestNamespace(t, func(ns1 string) {
+                       WithNewTestNamespace(t, func(ns2 string) {
+                               pl1 := v1.NewIntegrationPlatform(ns1, 
fmt.Sprintf("camel-k-%s", ns))
+                               pl.Spec.DeepCopyInto(&pl1.Spec)
+                               pl1.Spec.Build.Maven.Settings = v1.ValueSource{}
+                               pl1.SetOperatorID(fmt.Sprintf("camel-k-%s", ns))
+                               if err := TestClient().Create(TestContext, 
&pl1); err != nil {
+                                       t.Error(err)
+                                       t.FailNow()
+                               }
+
+                               Eventually(PlatformPhase(ns1), 
TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
+
+                               pl2 := v1.NewIntegrationPlatform(ns2, 
fmt.Sprintf("camel-k-%s", ns))
+                               pl.Spec.DeepCopyInto(&pl2.Spec)
+                               pl2.Spec.Build.Maven.Settings = v1.ValueSource{}
+                               pl2.SetOperatorID(fmt.Sprintf("camel-k-%s", ns))
+                               if err := TestClient().Create(TestContext, 
&pl2); err != nil {
+                                       t.Error(err)
+                                       t.FailNow()
+                               }
+
+                               Eventually(PlatformPhase(ns2), 
TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
+
+                               doKitBuildInNamespace(buildA, ns, 
TestTimeoutShort, kitOptions{
+                                       operatorID: fmt.Sprintf("camel-k-%s", 
ns),
+                                       dependencies: []string{
+                                               "camel:timer", "camel:log",
+                                       },
+                                       traits: []string{
+                                               
"builder.properties=build-property=A",
+                                       },
+                               }, v1.BuildPhaseRunning, 
v1.IntegrationKitPhaseBuildRunning)
+
+                               doKitBuildInNamespace(buildB, ns1, 
TestTimeoutShort, kitOptions{
+                                       operatorID: fmt.Sprintf("camel-k-%s", 
ns),
+                                       dependencies: []string{
+                                               "camel:timer", "camel:log",
+                                       },
+                                       traits: []string{
+                                               
"builder.properties=build-property=B",
+                                       },
+                               }, v1.BuildPhaseRunning, 
v1.IntegrationKitPhaseBuildRunning)
+
+                               doKitBuildInNamespace(buildC, ns2, 
TestTimeoutShort, kitOptions{
+                                       operatorID: fmt.Sprintf("camel-k-%s", 
ns),
+                                       dependencies: []string{
+                                               "camel:timer", "camel:log",
+                                       },
+                                       traits: []string{
+                                               
"builder.properties=build-property=C",
+                                       },
+                               }, v1.BuildPhaseScheduling, 
v1.IntegrationKitPhaseNone)
+
+                               var notExceedsMaxBuildLimit = 
func(runningBuilds int) bool {
+                                       return runningBuilds <= 2
+                               }
+
+                               limit := 0
+                               for limit < 5 && BuildPhase(ns, buildA)() == 
v1.BuildPhaseRunning {

Review Comment:
   For the sake of test this is not a problem as, in case it hangs 
indefinitely, there is a timeout on the whole suite of tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to