p2p/simulations : avoid duplicate unsubscribe

This commit is contained in:
ucwong 2024-01-05 03:53:25 +08:00
parent e3eeb64c94
commit 8b95e77770

View file

@ -76,7 +76,11 @@ func TestSnapshot(t *testing.T) {
// subscribe to peer events // subscribe to peer events
evC := make(chan *Event) evC := make(chan *Event)
sub := network.Events().Subscribe(evC) sub := network.Events().Subscribe(evC)
defer sub.Unsubscribe() defer func() {
if !sub.Closed() {
sub.Unsubscribe()
}
}()
// connect nodes in a ring // connect nodes in a ring
// spawn separate thread to avoid deadlock in the event listeners // spawn separate thread to avoid deadlock in the event listeners