Browse Source
pstoremanager: fix test timeout (#1588)
* Wait for event to be sent before we close
* Add timeout on channel
pull/1592/head
Marco Munizaga
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
17 additions and
2 deletions
-
p2p/host/pstoremanager/pstoremanager_test.go
|
|
@ -86,13 +86,28 @@ func TestClose(t *testing.T) { |
|
|
|
|
|
|
|
emitter, err := eventBus.Emitter(new(event.EvtPeerConnectednessChanged)) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
sub, err := eventBus.Subscribe(&event.EvtPeerConnectednessChanged{}) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
require.NoError(t, emitter.Emit(event.EvtPeerConnectednessChanged{ |
|
|
|
Peer: "foobar", |
|
|
|
Connectedness: network.NotConnected, |
|
|
|
})) |
|
|
|
time.Sleep(10 * time.Millisecond) // make sure the event is sent before we close
|
|
|
|
|
|
|
|
// make sure the event is sent before we close
|
|
|
|
select { |
|
|
|
case <-sub.Out(): |
|
|
|
case <-time.After(5 * time.Second): |
|
|
|
t.Fatalf("Hit timeout") |
|
|
|
} |
|
|
|
|
|
|
|
done := make(chan struct{}) |
|
|
|
pstore.EXPECT().RemovePeer(peer.ID("foobar")).Do(func(peer.ID) { close(done) }) |
|
|
|
require.NoError(t, man.Close()) |
|
|
|
<-done |
|
|
|
select { |
|
|
|
case <-done: |
|
|
|
case <-time.After(5 * time.Second): |
|
|
|
t.Fatalf("Hit timeout") |
|
|
|
} |
|
|
|
} |
|
|
|