From 3641bfe5d03af71fcbfaa3065b90198da13646c3 Mon Sep 17 00:00:00 2001 From: Jefferson Ramos Date: Wed, 18 Oct 2023 14:28:26 -0300 Subject: [PATCH] test improvements remove deprecates avoid nils, bump go version 1.20.x (#2032) * test: improvements on e2e extended test: remove deprecates, avoid nils and improve match conditions * update go version on ci to 1.20.x --- .github/workflows/build.yaml | 2 +- .github/workflows/check.yaml | 2 +- .github/workflows/ci.yaml | 14 +++++------ .github/workflows/schema.yaml | 2 +- .../workflows/test-e2e-oncluster-runtime.yaml | 2 +- .github/workflows/test-e2e-oncluster.yaml | 2 +- .github/workflows/test-e2e-runtime.yaml | 2 +- .github/workflows/test-e2e.yaml | 2 +- .github/workflows/test-embedded-fs.yaml | 2 +- .github/workflows/test-integration.yaml | 2 +- .github/workflows/test-podman.yaml | 2 +- .github/workflows/test-unit.yaml | 2 +- hack/allocate.sh | 1 + pkg/functions/client_int_test.go | 25 +++++++++++++++++++ test/common/readycheck.go | 5 ++-- test/e2e/scenario_extended_flow_test.go | 18 +++++++++---- test/e2e/scenario_no_container_test.go | 2 +- 17 files changed, 61 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index bdb8fa91..af21b464 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -7,7 +7,7 @@ jobs: name: Build strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest", "windows-latest", "macos-latest"] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 68f6b3f5..d7016e93 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -7,7 +7,7 @@ jobs: name: Check Source strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index faef31d0..fec48ad4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.20.2" + go-version: "1.20.x" - name: Lint run: make check && make check-templates - name: Check that 'func.yaml schema' is up-to-date @@ -22,7 +22,7 @@ jobs: test-unit: strategy: matrix: - go: [ 1.20.2 ] + go: [ 1.20.x ] java: [ 17 ] os: [ "ubuntu-latest", "windows-latest", "macos-latest" ] runs-on: ${{ matrix.os }} @@ -50,7 +50,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.20.2" + go-version: "1.20.x" - name: Install Binaries run: ./hack/binaries.sh - name: Allocate Cluster @@ -67,7 +67,7 @@ jobs: e2e-test: strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: @@ -91,7 +91,7 @@ jobs: e2e-on-cluster-test: strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: @@ -126,7 +126,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.20.2" + go-version: "1.20.x" # Standard build tasks - name: Build run: make cross-platform @@ -167,6 +167,6 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.20.2" + go-version: "1.20.x" - uses: imjasonh/setup-ko@v0.6 - run: ko build --platform=linux/ppc64le,linux/s390x,linux/amd64,linux/arm64 -B ./cmd/func diff --git a/.github/workflows/schema.yaml b/.github/workflows/schema.yaml index 3bf7fd87..8a53403e 100644 --- a/.github/workflows/schema.yaml +++ b/.github/workflows/schema.yaml @@ -7,7 +7,7 @@ jobs: name: Check Schema strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/test-e2e-oncluster-runtime.yaml b/.github/workflows/test-e2e-oncluster-runtime.yaml index dde9088b..7eb883a4 100644 --- a/.github/workflows/test-e2e-oncluster-runtime.yaml +++ b/.github/workflows/test-e2e-oncluster-runtime.yaml @@ -8,7 +8,7 @@ jobs: continue-on-error: true strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] func_builder: ["pack", "s2i"] runs-on: ${{ matrix.os }} diff --git a/.github/workflows/test-e2e-oncluster.yaml b/.github/workflows/test-e2e-oncluster.yaml index c7770715..35c4bdc7 100644 --- a/.github/workflows/test-e2e-oncluster.yaml +++ b/.github/workflows/test-e2e-oncluster.yaml @@ -7,7 +7,7 @@ jobs: name: On Cluster Test strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/test-e2e-runtime.yaml b/.github/workflows/test-e2e-runtime.yaml index 59a2b67b..2b558bd5 100644 --- a/.github/workflows/test-e2e-runtime.yaml +++ b/.github/workflows/test-e2e-runtime.yaml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: 1.20.2 + go-version: 1.20.x - name: Install Binaries run: ./hack/binaries.sh - name: Allocate Cluster diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index cf1ab013..b2d0ea51 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -7,7 +7,7 @@ jobs: name: E2E Test strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/test-embedded-fs.yaml b/.github/workflows/test-embedded-fs.yaml index 395c603e..91d11e24 100644 --- a/.github/workflows/test-embedded-fs.yaml +++ b/.github/workflows/test-embedded-fs.yaml @@ -7,7 +7,7 @@ jobs: name: Func Embedded FS Test strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/test-integration.yaml b/.github/workflows/test-integration.yaml index fc46f001..86f4a77d 100644 --- a/.github/workflows/test-integration.yaml +++ b/.github/workflows/test-integration.yaml @@ -7,7 +7,7 @@ jobs: name: Integration Test strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/test-podman.yaml b/.github/workflows/test-podman.yaml index 88392913..f19a195f 100644 --- a/.github/workflows/test-podman.yaml +++ b/.github/workflows/test-podman.yaml @@ -7,7 +7,7 @@ jobs: name: Podman Test strategy: matrix: - go: [1.20.2] + go: [1.20.x] os: ["ubuntu-latest"] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 74246ef2..e4010923 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -7,7 +7,7 @@ jobs: name: Unit Test strategy: matrix: - go: [1.20.2] + go: [1.20.x] java: [17] os: ["ubuntu-latest", "windows-latest", "macos-latest"] runs-on: ${{ matrix.os }} diff --git a/hack/allocate.sh b/hack/allocate.sh index 930ecdde..024d8611 100755 --- a/hack/allocate.sh +++ b/hack/allocate.sh @@ -131,6 +131,7 @@ networking() { echo "Install load balancer." kubectl apply -f "https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml" + sleep 5 kubectl wait --namespace metallb-system \ --for=condition=ready pod \ --selector=app=metallb \ diff --git a/pkg/functions/client_int_test.go b/pkg/functions/client_int_test.go index 7517ca48..88e9d109 100644 --- a/pkg/functions/client_int_test.go +++ b/pkg/functions/client_int_test.go @@ -14,6 +14,10 @@ import ( "testing" "time" + "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/client" + "knative.dev/func/pkg/builders/buildpacks" "knative.dev/func/pkg/docker" fn "knative.dev/func/pkg/functions" @@ -530,6 +534,27 @@ func del(t *testing.T, c *fn.Client, name string) { if err := c.Remove(context.Background(), fn.Function{Name: name}, false); err != nil { t.Fatal(err) } + cli, _, err := docker.NewClient(client.DefaultDockerHost) + if err != nil { + t.Fatal(err) + } + defer cli.Close() + opts := volume.ListOptions{ + Filters: filters.NewArgs( + filters.Arg("name", fmt.Sprintf("pack-cache-func_%s_*", name)), + ), + } + resp, err := cli.VolumeList(context.Background(), opts) + if err != nil { + t.Fatal(err) + } + for _, vol := range resp.Volumes { + t.Log("deleting volume:", vol.Name) + err = cli.VolumeRemove(context.Background(), vol.Name, true) + if err != nil { + t.Fatal(err) + } + } } // waitFor the named function to become available in List output. diff --git a/test/common/readycheck.go b/test/common/readycheck.go index 4b4c4ab6..5f26a910 100644 --- a/test/common/readycheck.go +++ b/test/common/readycheck.go @@ -1,6 +1,7 @@ package common import ( + "context" "testing" "time" @@ -8,7 +9,7 @@ import ( ) func WaitForFunctionReady(t *testing.T, functionName string) (revisionName string, functionUrl string) { - err := wait.PollImmediate(5*time.Second, 1*time.Minute, func() (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 1*time.Minute, true, func(ctx context.Context) (done bool, err error) { revisionName, functionUrl = GetKnativeServiceRevisionAndUrl(t, functionName) t.Logf("Waiting function to get ready (revision [%v])", revisionName) return revisionName != "", nil @@ -21,7 +22,7 @@ func WaitForFunctionReady(t *testing.T, functionName string) (revisionName strin // NewRevisionCheck waits for a new revision to report as ready func WaitForNewRevisionReady(t *testing.T, previousRevision string, functionName string) (newRevision string) { - err := wait.PollImmediate(5*time.Second, 1*time.Minute, func() (done bool, err error) { + err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 1*time.Minute, true, func(ctx context.Context) (done bool, err error) { newRevision = GetCurrentServiceRevision(t, functionName) t.Logf("Waiting for new revision deployment (previous revision [%v], current revision [%v])", previousRevision, newRevision) return newRevision != "" && newRevision != previousRevision, nil diff --git a/test/e2e/scenario_extended_flow_test.go b/test/e2e/scenario_extended_flow_test.go index 7cf22dbb..1ffaa053 100644 --- a/test/e2e/scenario_extended_flow_test.go +++ b/test/e2e/scenario_extended_flow_test.go @@ -60,11 +60,19 @@ func TestFunctionExtendedFlow(t *testing.T) { funcPort, attempts := "", 0 for funcPort == "" && attempts < 10 { t.Logf("----Function Output:\n%v\n", stdout.String()) - matches := regexp.MustCompile("Running on host port (.*)").FindStringSubmatch(stdout.String()) + findPort := func(exp string, msg string) (port string) { + matches := regexp.MustCompile(exp).FindStringSubmatch(msg) + if len(matches) > 1 { + port = matches[1] + } + return + } + funcPort = findPort("Running on host port (.*)", stdout.String()) + if funcPort == "" { + funcPort = findPort("Function started on port (.*)", stdout.String()) + } attempts++ - if len(matches) > 1 { - funcPort = matches[1] - } else { + if funcPort == "" { time.Sleep(200 * time.Millisecond) } } @@ -92,7 +100,7 @@ func TestFunctionExtendedFlow(t *testing.T) { time.Sleep(time.Second) // GET Function HTTP Endpoint - _, bodyResp := testhttp.TestGet(t, "http://:"+funcPort+"?message=local") + _, bodyResp := testhttp.TestGet(t, "http://localhost:"+funcPort+"?message=local") assert.Assert(t, strings.Contains(bodyResp, `{"message":"local"}`), "function response does not contain expected body.") // --------------------------- diff --git a/test/e2e/scenario_no_container_test.go b/test/e2e/scenario_no_container_test.go index f00e52e3..e69145bf 100644 --- a/test/e2e/scenario_no_container_test.go +++ b/test/e2e/scenario_no_container_test.go @@ -77,7 +77,7 @@ func TestFunctionRunWithoutContainer(t *testing.T) { time.Sleep(time.Second) // Assert Function endpoint responds - _, bodyResp := testhttp.TestGet(t, "http://:"+funcPort+"?message=run-on-host") + _, bodyResp := testhttp.TestGet(t, "http://localhost:"+funcPort+"?message=run-on-host") assert.Assert(t, strings.Contains(bodyResp, `GET /?message=run-on-host`), "function response does not contain expected body.") // Assert Func were not built