swarm: Fix T.Fatal inside a goroutine in tests (#18409)
* swarm/storage: fix T.Fatal inside a goroutine * swarm/network/simulation: fix T.Fatal inside a goroutine * swarm/network/stream: fix T.Fatal inside a goroutine * swarm/network/simulation: consistent failures in TestPeerEventsTimeout * swarm/network/simulation: rename sendRunSignal to triggerSimulationRun
This commit is contained in:
committed by
Viktor Trón
parent
81f04fa606
commit
d70c4faf20
@@ -81,6 +81,7 @@ func TestPeerEventsTimeout(t *testing.T) {
|
||||
events := sim.PeerEvents(ctx, sim.NodeIDs())
|
||||
|
||||
done := make(chan struct{})
|
||||
errC := make(chan error)
|
||||
go func() {
|
||||
for e := range events {
|
||||
if e.Error == context.Canceled {
|
||||
@@ -90,14 +91,16 @@ func TestPeerEventsTimeout(t *testing.T) {
|
||||
close(done)
|
||||
return
|
||||
} else {
|
||||
t.Fatal(e.Error)
|
||||
errC <- e.Error
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-time.After(time.Second):
|
||||
t.Error("no context deadline received")
|
||||
t.Fatal("no context deadline received")
|
||||
case err := <-errC:
|
||||
t.Fatal(err)
|
||||
case <-done:
|
||||
// all good, context deadline detected
|
||||
}
|
||||
|
Reference in New Issue
Block a user