Poll server in Go unit tests

This commit is contained in:
Chen-I Lim 2021-01-06 12:55:14 -08:00
parent 0571264d1f
commit 14ab03cb97

View file

@ -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
}