diff options
author | Janoš Guljaš <janos@users.noreply.github.com> | 2019-01-09 14:05:55 +0800 |
---|---|---|
committer | Viktor Trón <viktor.tron@gmail.com> | 2019-01-09 14:05:55 +0800 |
commit | d70c4faf20d5533e30eec5cbb9b5180eb837b78c (patch) | |
tree | b059c20fa8093b6f8479a7706077cc24cdcaba0e /swarm/network/stream/snapshot_sync_test.go | |
parent | 81f04fa60608a67bac693879acbe086562d3970d (diff) | |
download | dexon-d70c4faf20d5533e30eec5cbb9b5180eb837b78c.tar dexon-d70c4faf20d5533e30eec5cbb9b5180eb837b78c.tar.gz dexon-d70c4faf20d5533e30eec5cbb9b5180eb837b78c.tar.bz2 dexon-d70c4faf20d5533e30eec5cbb9b5180eb837b78c.tar.lz dexon-d70c4faf20d5533e30eec5cbb9b5180eb837b78c.tar.xz dexon-d70c4faf20d5533e30eec5cbb9b5180eb837b78c.tar.zst dexon-d70c4faf20d5533e30eec5cbb9b5180eb837b78c.zip |
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
Diffstat (limited to 'swarm/network/stream/snapshot_sync_test.go')
-rw-r--r-- | swarm/network/stream/snapshot_sync_test.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/swarm/network/stream/snapshot_sync_test.go b/swarm/network/stream/snapshot_sync_test.go index f86d9acca..7a883644b 100644 --- a/swarm/network/stream/snapshot_sync_test.go +++ b/swarm/network/stream/snapshot_sync_test.go @@ -21,6 +21,7 @@ import ( "os" "runtime" "sync" + "sync/atomic" "testing" "time" @@ -213,11 +214,13 @@ func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) { simulation.NewPeerEventsFilter().Drop(), ) + var disconnected atomic.Value go func() { for d := range disconnections { - log.Error("peer drop", "node", d.NodeID, "peer", d.PeerID) - t.Fatal("unexpected disconnect") - cancelSimRun() + if d.Error != nil { + log.Error("peer drop", "node", d.NodeID, "peer", d.PeerID) + disconnected.Store(true) + } } }() @@ -226,6 +229,9 @@ func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) { if result.Error != nil { t.Fatal(result.Error) } + if yes, ok := disconnected.Load().(bool); ok && yes { + t.Fatal("disconnect events received") + } log.Info("Simulation ended") } @@ -395,11 +401,13 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int) simulation.NewPeerEventsFilter().Drop(), ) + var disconnected atomic.Value go func() { for d := range disconnections { - log.Error("peer drop", "node", d.NodeID, "peer", d.PeerID) - t.Fatal("unexpected disconnect") - cancelSimRun() + if d.Error != nil { + log.Error("peer drop", "node", d.NodeID, "peer", d.PeerID) + disconnected.Store(true) + } } }() @@ -514,6 +522,9 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int) return result.Error } + if yes, ok := disconnected.Load().(bool); ok && yes { + t.Fatal("disconnect events received") + } log.Info("Simulation ended") return nil } |