This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 6ce7c07c429c7a486434f8f9c24612d73183fc61
Author: Luca Burgazzoli <lburgazz...@gmail.com>
AuthorDate: Mon Jan 23 17:43:03 2023 +0100

    chore(test): improve locale e2e tests
    
    - remove goroutine for build related test as not needed
    - added waiting group to wait for async tasks completion
---
 e2e/local/local_build_test.go   | 68 ++++++++++-------------------------------
 e2e/local/local_inspect_test.go | 20 +++---------
 e2e/local/local_run_test.go     | 33 +++++++++++++++++---
 e2e/support/util/log_scanner.go |  5 +++
 4 files changed, 55 insertions(+), 71 deletions(-)

diff --git a/e2e/local/local_build_test.go b/e2e/local/local_build_test.go
index 543f0da2c..de8ba6a32 100644
--- a/e2e/local/local_build_test.go
+++ b/e2e/local/local_build_test.go
@@ -25,7 +25,6 @@ import (
        "fmt"
        "io"
        "strings"
-       "sync"
        "testing"
 
        . "github.com/onsi/gomega"
@@ -55,7 +54,7 @@ func getCamelVersion() string {
 func TestLocalBuild(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -71,11 +70,7 @@ func TestLocalBuild(t *testing.T) {
        msgTagged := "Successfully tagged"
        logScanner := testutil.NewLogScanner(ctx, piper, msgTagged, image)
 
-       go func() {
-               err := kamelBuild.Execute()
-               assert.NoError(t, err)
-               cancel()
-       }()
+       Expect(kamelBuild.Execute()).To(BeNil())
 
        Eventually(logScanner.IsFound(msgTagged), 
TestTimeoutMedium).Should(BeTrue())
        Eventually(logScanner.IsFound(image), 
TestTimeoutMedium).Should(BeTrue())
@@ -85,7 +80,7 @@ func TestLocalBuild(t *testing.T) {
 func TestLocalBuildWithTrait(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -102,11 +97,7 @@ func TestLocalBuildWithTrait(t *testing.T) {
        msgTagged := "Successfully tagged"
        logScanner := testutil.NewLogScanner(ctx, piper, msgWarning, msgTagged, 
image)
 
-       go func() {
-               err := kamelBuild.Execute()
-               assert.NoError(t, err)
-               cancel()
-       }()
+       Expect(kamelBuild.Execute()).To(BeNil())
 
        Eventually(logScanner.IsFound(msgWarning), 
TestTimeoutMedium).Should(BeTrue())
        Eventually(logScanner.IsFound(msgTagged), 
TestTimeoutMedium).Should(BeTrue())
@@ -117,7 +108,7 @@ func TestLocalBuildWithTrait(t *testing.T) {
 func TestLocalBuildWithInvalidDependency(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -138,25 +129,17 @@ func TestLocalBuildWithInvalidDependency(t *testing.T) {
        warn3 := "Warning: do not use 
mvn:org.apache.camel.quarkus:camel-quarkus-netty:2.11.0. Use camel:netty 
instead"
        logScanner := testutil.NewLogScanner(ctx, piper, warn1, warn2, warn3)
 
-       var wg sync.WaitGroup
-       wg.Add(1)
-       go func() {
-               defer wg.Done()
-               err := kamelBuild.Execute()
-               assert.Error(t, err)
-               cancel()
-       }()
+       Expect(kamelBuild.Execute()).To(Not(BeNil()))
 
        Eventually(logScanner.IsFound(warn1), TestTimeoutShort).Should(BeTrue())
        Eventually(logScanner.IsFound(warn2), TestTimeoutShort).Should(BeTrue())
        Eventually(logScanner.IsFound(warn3), TestTimeoutShort).Should(BeTrue())
-       wg.Wait()
 }
 
 func TestLocalBuildIntegrationDirectory(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
 
        file := testutil.MakeTempCopy(t, "files/yaml.yaml")
@@ -164,10 +147,7 @@ func TestLocalBuildIntegrationDirectory(t *testing.T) {
 
        kamelBuild := kamelWithContext(ctx, "local", "build", file, 
"--integration-directory", dir)
 
-       go func() {
-               err := kamelBuild.Execute()
-               assert.NoError(t, err)
-       }()
+       Expect(kamelBuild.Execute()).To(BeNil())
 
        Eventually(dir+"/dependencies", TestTimeoutShort).Should(BeADirectory())
        Eventually(dependency(dir, "org.apache.camel.camel-timer-%s.jar", 
camelVersion), TestTimeoutShort).Should(BeAnExistingFile())
@@ -183,7 +163,7 @@ func TestLocalBuildIntegrationDirectory(t *testing.T) {
 func TestLocalBuildIntegrationDirectoryWithSpaces(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
 
        file := testutil.MakeTempCopy(t, "files/yaml.yaml")
@@ -191,12 +171,7 @@ func TestLocalBuildIntegrationDirectoryWithSpaces(t 
*testing.T) {
 
        kamelBuild := kamelWithContext(ctx, "local", "build", file, 
"--integration-directory", dir)
 
-       go func() {
-               err := kamelBuild.Execute()
-               assert.NoError(t, err)
-               cancel()
-       }()
-
+       Expect(kamelBuild.Execute()).To(BeNil())
        Eventually(dir+"/dependencies", TestTimeoutShort).Should(BeADirectory())
        Eventually(dependency(dir, "org.apache.camel.camel-timer-%s.jar", 
camelVersion), TestTimeoutShort).Should(BeAnExistingFile())
        Eventually(dependency(dir, "org.apache.camel.camel-log-%s.jar", 
camelVersion), TestTimeoutShort).Should(BeAnExistingFile())
@@ -207,7 +182,7 @@ func TestLocalBuildIntegrationDirectoryWithSpaces(t 
*testing.T) {
 func TestLocalBuildIntegrationDirectoryWithMultiBytes(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
 
        file := testutil.MakeTempCopy(t, "files/yaml.yaml")
@@ -215,11 +190,7 @@ func TestLocalBuildIntegrationDirectoryWithMultiBytes(t 
*testing.T) {
 
        kamelBuild := kamelWithContext(ctx, "local", "build", file, 
"--integration-directory", dir)
 
-       go func() {
-               err := kamelBuild.Execute()
-               assert.NoError(t, err)
-               cancel()
-       }()
+       Expect(kamelBuild.Execute()).To(BeNil())
 
        Eventually(dir+"/dependencies", TestTimeoutShort).Should(BeADirectory())
        Eventually(dependency(dir, "org.apache.camel.camel-timer-%s.jar", 
camelVersion), TestTimeoutShort).Should(BeAnExistingFile())
@@ -231,7 +202,7 @@ func TestLocalBuildIntegrationDirectoryWithMultiBytes(t 
*testing.T) {
 func TestLocalBuildDependenciesOnly(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
 
        file := testutil.MakeTempCopy(t, "files/yaml.yaml")
@@ -239,11 +210,7 @@ func TestLocalBuildDependenciesOnly(t *testing.T) {
 
        kamelBuild := kamelWithContext(ctx, "local", "build", file, 
"--integration-directory", dir, "--dependencies-only", "-d", "camel-amqp")
 
-       go func() {
-               err := kamelBuild.Execute()
-               assert.NoError(t, err)
-               cancel()
-       }()
+       Expect(kamelBuild.Execute()).To(BeNil())
 
        Eventually(dir+"/dependencies", TestTimeoutShort).Should(BeADirectory())
        Eventually(dependency(dir, "org.apache.camel.camel-timer-%s.jar", 
camelVersion), TestTimeoutShort).Should(BeAnExistingFile())
@@ -256,7 +223,7 @@ func TestLocalBuildDependenciesOnly(t *testing.T) {
 func TestLocalBuildModelineDependencies(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
 
        file := testutil.MakeTempCopy(t, "files/dependency.groovy")
@@ -264,10 +231,7 @@ func TestLocalBuildModelineDependencies(t *testing.T) {
 
        kamelBuild := kamelWithContext(ctx, "local", "build", file, 
"--integration-directory", dir, "-d", "camel-amqp")
 
-       go func() {
-               err := kamelBuild.Execute()
-               assert.NoError(t, err)
-       }()
+       Expect(kamelBuild.Execute()).To(BeNil())
 
        Eventually(dir+"/dependencies", TestTimeoutShort).Should(BeADirectory())
        Eventually(dependency(dir, "org.apache.camel.camel-timer-%s.jar", 
camelVersion), TestTimeoutShort).Should(BeAnExistingFile())
diff --git a/e2e/local/local_inspect_test.go b/e2e/local/local_inspect_test.go
index 902eac973..a1a1621d2 100644
--- a/e2e/local/local_inspect_test.go
+++ b/e2e/local/local_inspect_test.go
@@ -25,17 +25,15 @@ import (
        "io"
        "testing"
 
-       . "github.com/onsi/gomega"
-       "github.com/stretchr/testify/assert"
-
        . "github.com/apache/camel-k/e2e/support"
        testutil "github.com/apache/camel-k/e2e/support/util"
+       . "github.com/onsi/gomega"
 )
 
 func TestLocalInspect(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -53,11 +51,7 @@ func TestLocalInspect(t *testing.T) {
                //"mvn:org.apache.camel.quarkus:camel-quarkus-yaml-dsl",
        )
 
-       go func() {
-               err := kamelInspect.Execute()
-               assert.NoError(t, err)
-               cancel()
-       }()
+       Expect(kamelInspect.Execute()).To(BeNil())
 
        Eventually(logScanner.IsFound("camel:log"), 
TestTimeoutShort).Should(BeTrue())
        Eventually(logScanner.IsFound("camel:timer"), 
TestTimeoutShort).Should(BeTrue())
@@ -67,7 +61,7 @@ func TestLocalInspect(t *testing.T) {
 func TestLocalInspectWithDependencies(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -93,11 +87,7 @@ func TestLocalInspectWithDependencies(t *testing.T) {
                "camel:timer",
        )
 
-       go func() {
-               err := kamelInspect.Execute()
-               assert.NoError(t, err)
-               cancel()
-       }()
+       Expect(kamelInspect.Execute()).To(BeNil())
 
        Eventually(logScanner.IsFound(warn1), TestTimeoutShort).Should(BeTrue())
        Eventually(logScanner.IsFound(warn2), TestTimeoutShort).Should(BeTrue())
diff --git a/e2e/local/local_run_test.go b/e2e/local/local_run_test.go
index 9ac6f864b..0e6ceec75 100644
--- a/e2e/local/local_run_test.go
+++ b/e2e/local/local_run_test.go
@@ -38,7 +38,7 @@ import (
 func TestLocalRun(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -52,7 +52,12 @@ func TestLocalRun(t *testing.T) {
 
        logScanner := testutil.NewLogScanner(ctx, piper, "Magicstring!")
 
+       var wg sync.WaitGroup
+       wg.Add(1)
+
        go func() {
+               defer wg.Done()
+
                _ = kamelRun.Execute()
                cancel()
        }()
@@ -63,7 +68,7 @@ func TestLocalRun(t *testing.T) {
 func TestLocalRunWithDependencies(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -77,7 +82,11 @@ func TestLocalRunWithDependencies(t *testing.T) {
 
        logScanner := testutil.NewLogScanner(ctx, piper, "Magicstring!")
 
+       var wg sync.WaitGroup
+       wg.Add(1)
+
        go func() {
+               defer wg.Done()
                _ = kamelRun.Execute()
                cancel()
        }()
@@ -88,7 +97,7 @@ func TestLocalRunWithDependencies(t *testing.T) {
 func TestLocalRunWithInvalidDependency(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -110,8 +119,10 @@ func TestLocalRunWithInvalidDependency(t *testing.T) {
 
        var wg sync.WaitGroup
        wg.Add(1)
+
        go func() {
                defer wg.Done()
+
                err := kamelRun.Execute()
                assert.Error(t, err)
                cancel()
@@ -126,7 +137,7 @@ func TestLocalRunWithInvalidDependency(t *testing.T) {
 func TestLocalRunContainerize(t *testing.T) {
        RegisterTestingT(t)
 
-       ctx, cancel := context.WithCancel(TestContext)
+       ctx, cancel := context.WithTimeout(TestContext, TestTimeoutMedium)
        defer cancel()
        piper, pipew := io.Pipe()
        defer pipew.Close()
@@ -141,8 +152,12 @@ func TestLocalRunContainerize(t *testing.T) {
 
        logScanner := testutil.NewLogScanner(ctx, piper, "Magicstring!")
 
+       var wg sync.WaitGroup
+       wg.Add(1)
+
        defer StopDockerContainers()
        go func() {
+               defer wg.Done()
                _ = kamelRun.Execute()
                cancel()
        }()
@@ -162,7 +177,12 @@ func TestLocalRunIntegrationDirectory(t *testing.T) {
 
        kamelBuild := kamelWithContext(ctx1, "local", "build", file, 
"--integration-directory", dir)
 
+       var wg sync.WaitGroup
+       wg.Add(1)
+
        go func() {
+               defer wg.Done()
+
                err := kamelBuild.Execute()
                assert.NoError(t, err)
                cancel1()
@@ -184,7 +204,12 @@ func TestLocalRunIntegrationDirectory(t *testing.T) {
 
        logScanner := testutil.NewLogScanner(ctx2, piper, "Magicstring!")
 
+       var wg2 sync.WaitGroup
+       wg2.Add(1)
+
        go func() {
+               defer wg2.Done()
+
                _ = kamelRun.Execute()
                cancel2()
        }()
diff --git a/e2e/support/util/log_scanner.go b/e2e/support/util/log_scanner.go
index 82262d889..7508bc4a2 100644
--- a/e2e/support/util/log_scanner.go
+++ b/e2e/support/util/log_scanner.go
@@ -72,3 +72,8 @@ func (s *LogScanner) IsFound(value string) func() bool {
                return s.values[value]
        }
 }
+
+// Contains returns if the string has been found in the logs
+func (s *LogScanner) Contains(value string) bool {
+       return s.values[value]
+}

Reply via email to