Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pstoremanager: fix test timeout #1588

Merged
merged 2 commits into from
Jun 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions p2p/host/pstoremanager/pstoremanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}