From 9eb7acf061a689d5bb17f2e0b3a8e904827969e2 Mon Sep 17 00:00:00 2001 From: neha_gupta Date: Wed, 30 Nov 2022 17:31:19 +0530 Subject: [PATCH] wait in testcase until server starts (#2648) --- pkg/router/auth_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/router/auth_test.go b/pkg/router/auth_test.go index 7605bf48..316f19b6 100644 --- a/pkg/router/auth_test.go +++ b/pkg/router/auth_test.go @@ -9,8 +9,10 @@ import ( "net/http" "os" "testing" + "time" "github.com/gorilla/mux" + "k8s.io/apimachinery/pkg/util/wait" fv1 "github.com/fission/fission/pkg/apis/core/v1" config "github.com/fission/fission/pkg/featureconfig" @@ -104,6 +106,23 @@ func TestRouterAuth(t *testing.T) { }, } + backOff := wait.Backoff{Duration: 1 * time.Second, Cap: 20 * time.Second, Steps: 5} + + condition := func() (bool, error) { + rBody := bytes.NewBuffer(postBody) + _, err := http.Post("http://localhost:8990/auth/login", "application/json", rBody) + if err != nil { + return false, nil + } + + return true, nil + } + + err := wait.ExponentialBackoff(backOff, condition) + if err != nil { + t.Error(err) + } + loginResp, err := http.Post("http://localhost:8990/auth/login", "application/json", responseBody) if err != nil { t.Error(err)