From c50466fb256e811f4a91931794a4f5e95d40b1bf Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Tue, 5 Sep 2017 15:46:00 +0100 Subject: [PATCH] Wait for platform presence in fluxsvc test One source of flakes appears to be the race between the platform being registered and seeing if the platform is registered (both `TestFluxsvc_Register` and `TestFluxsvc_Ping`). This change forces those tests to block until the platform has demonstrably subscribed, or fail if it does not happen within five seconds. --- cmd/fluxsvc/fluxsvc_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/fluxsvc/fluxsvc_test.go b/cmd/fluxsvc/fluxsvc_test.go index 07db43e10..236dd0df6 100644 --- a/cmd/fluxsvc/fluxsvc_test.go +++ b/cmd/fluxsvc/fluxsvc_test.go @@ -114,7 +114,10 @@ func setup(t *testing.T) { }, } done := make(chan error) - messageBus.Subscribe(id, mockPlatform, done) // For ListService + messageBus.Subscribe(id, mockPlatform, done) + if err := messageBus.AwaitPresence(id, 5*time.Second); err != nil { + t.Errorf("Timed out waiting for presence of mockPlatform") + } // History hDb, _ := historysql.NewSQL(dbDriver, databaseSource) @@ -346,7 +349,7 @@ func TestFluxsvc_Ping(t *testing.T) { if err != nil { t.Fatal(err) } - t.Fatal("Request should have been ok but got %q, body:\n%v", resp.Status, body) + t.Fatal("Request should have been ok but got %q, body:\n%q", resp.Status, string(body)) } } @@ -371,6 +374,6 @@ func TestFluxsvc_Register(t *testing.T) { if err != nil { t.Fatal(err) } - t.Fatal("Request should have been ok but got %q, body:\n%v", resp.Status, body) + t.Fatal("Request should have been ok but got %q, body:\n%q", resp.Status, string(body)) } }