From 1eb846cb1e17132ae9c1756ccfbb0e422957bc7b Mon Sep 17 00:00:00 2001 From: Shulhan Date: Mon, 11 Jul 2022 22:57:40 +0700 Subject: test: wait for server before running the test On build.kilabit.info, 2 out 5 building this repository return an error dial tcp 127.0.0.1:5381: connect: connection refused This is due to server is not ready accepting connection while the test for client is already running. --- rescached_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rescached_test.go b/rescached_test.go index ebf480f..6ec38e8 100644 --- a/rescached_test.go +++ b/rescached_test.go @@ -7,6 +7,7 @@ import ( "log" "os" "testing" + "time" libhttp "github.com/shuLhan/share/lib/http" ) @@ -25,6 +26,7 @@ func TestMain(m *testing.M) { var ( err error testStatus int + x int ) go mockBlockdServer() @@ -48,6 +50,16 @@ func TestMain(m *testing.M) { resc = NewClient("http://"+testEnv.WUIListen, false) + // Loop 10 times until server ready for testing. + for x = 0; x < 10; x++ { + time.Sleep(500) + _, err = resc.Env() + if err != nil { + continue + } + break + } + testStatus = m.Run() os.Exit(testStatus) -- cgit v1.3