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.
This commit is contained in:
James Shubin
2019-04-11 19:56:01 -04:00
parent 859e4749ae
commit cacd14fcf8

View File

@@ -147,6 +147,7 @@ func ExampleSubscribedSignal() {
ready.Wait() // wait for all subscribes ready.Wait() // wait for all subscribes
fmt.Println("sending signal...") 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") fmt.Println("done sending signal")
wg.Wait() // wait for everyone to exit wg.Wait() // wait for everyone to exit
@@ -160,9 +161,9 @@ func ExampleSubscribedSignal() {
// (1) sending ack... // (1) sending ack...
// (2) sending ack... // (2) sending ack...
// (3) sending ack... // (3) sending ack...
// done sending ack
// done sending ack
// done sending ack
// done sending signal // done sending signal
// done sending ack
// done sending ack
// done sending ack
// exiting... // exiting...
} }