From cacd14fcf8fe29214c297c3d8ffef880be207072 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 11 Apr 2019 19:56:01 -0400 Subject: [PATCH] util: Make test more resistant to races This doesn't guarantee which print statement runs first, so the last part of it can race. Adding a sleep makes this highly unlikely. --- util/sync_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/util/sync_test.go b/util/sync_test.go index 00ce1f2e..e796a28a 100644 --- a/util/sync_test.go +++ b/util/sync_test.go @@ -146,7 +146,8 @@ func ExampleSubscribedSignal() { ready.Wait() // wait for all subscribes fmt.Println("sending signal...") - x.Send() // trigger! + x.Send() // trigger! + time.Sleep(1 * time.Second) // wait a bit so the next print doesn't race fmt.Println("done sending signal") wg.Wait() // wait for everyone to exit @@ -160,9 +161,9 @@ func ExampleSubscribedSignal() { // (1) sending ack... // (2) sending ack... // (3) sending ack... + // done sending ack + // done sending ack + // done sending ack // done sending signal - // done sending ack - // done sending ack - // done sending ack // exiting... }