Skip to content

Commit

Permalink
test: improvements on e2e extended test: remove deprecates, avoid nil…
Browse files Browse the repository at this point in the history
…s and improve match conditions
  • Loading branch information
jrangelramos committed Oct 18, 2023
1 parent 788f18c commit 30b6f37
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions hack/allocate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions test/common/readycheck.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package common

import (
"context"
"testing"
"time"

"k8s.io/apimachinery/pkg/util/wait"
)

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
Expand All @@ -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
Expand Down
18 changes: 13 additions & 5 deletions test/e2e/scenario_extended_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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.")

// ---------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/scenario_no_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30b6f37

Please sign in to comment.