From 14ab03cb97942d8bdd83cd3630bf82edffb184b0 Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Wed, 6 Jan 2021 12:55:14 -0800 Subject: [PATCH] Poll server in Go unit tests --- server/integrationtests/clienttestlib.go | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/server/integrationtests/clienttestlib.go b/server/integrationtests/clienttestlib.go index 233104f1e..b501acf31 100644 --- a/server/integrationtests/clienttestlib.go +++ b/server/integrationtests/clienttestlib.go @@ -1,7 +1,9 @@ package integrationtests import ( + "log" "net/http" + "time" "github.com/mattermost/mattermost-octo-tasks/server/client" "github.com/mattermost/mattermost-octo-tasks/server/server" @@ -43,6 +45,29 @@ func (th *TestHelper) InitBasic() *TestHelper { } }() + for { + URL := th.Server.Config().ServerRoot + log.Printf("Polling server at %v", URL) + resp, err := http.Get(URL) + if err != nil { + log.Println("Polling failed:", err) + time.Sleep(100 * time.Millisecond) + continue + } + resp.Body.Close() + + // Currently returns 404 + // if resp.StatusCode != http.StatusOK { + // log.Println("Not OK:", resp.StatusCode) + // continue + // } + + // Reached this point: server is up and running! + log.Println("Server ping OK, statusCode:", resp.StatusCode) + + break + } + return th }