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:
@@ -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...
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user