Skip to content

Commit

Permalink
swarm/network: DRY out repeated giga comment
Browse files Browse the repository at this point in the history
I not necessarily agree with the way we wait for event propagation.
But I truly disagree with having duplicated giga comments.
  • Loading branch information
Ferenc Szabo committed Jan 30, 2019
1 parent 8cfe1a6 commit 4b2f34c
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions swarm/network/simulation/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,7 @@ func TestStartStopNode(t *testing.T) {
t.Error("node not stopped")
}

// Sleep here to ensure that Network.watchPeerEvents defer function
// has set the `node.Up = false` before we start the node again.
// p2p/simulations/network.go:215
//
// The same node is stopped and started again, and upon start
// watchPeerEvents is started in a goroutine. If the node is stopped
// and then very quickly started, that goroutine may be scheduled later
// then start and force `node.Up = false` in its defer function.
// This will make this test unreliable.
time.Sleep(time.Second)
waitForPeerEventPropagation()

err = sim.StartNode(id)
if err != nil {
Expand Down Expand Up @@ -386,16 +377,7 @@ func TestStartStopRandomNode(t *testing.T) {
t.Fatal(err)
}

// Sleep here to ensure that Network.watchPeerEvents defer function
// has set the `node.Up = false` before we start the node again.
// p2p/simulations/network.go:215
//
// The same node is stopped and started again, and upon start
// watchPeerEvents is started in a goroutine. If the node is stopped
// and then very quickly started, that goroutine may be scheduled later
// then start and force `node.Up = false` in its defer function.
// This will make this test unreliable.
time.Sleep(time.Second)
waitForPeerEventPropagation()

idStarted, err := sim.StartRandomNode()
if err != nil {
Expand Down Expand Up @@ -431,16 +413,7 @@ func TestStartStopRandomNodes(t *testing.T) {
}
}

// Sleep here to ensure that Network.watchPeerEvents defer function
// has set the `node.Up = false` before we start the node again.
// p2p/simulations/network.go:215
//
// The same node is stopped and started again, and upon start
// watchPeerEvents is started in a goroutine. If the node is stopped
// and then very quickly started, that goroutine may be scheduled later
// then start and force `node.Up = false` in its defer function.
// This will make this test unreliable.
time.Sleep(time.Second)
waitForPeerEventPropagation()

ids, err = sim.StartRandomNodes(2)
if err != nil {
Expand All @@ -457,3 +430,15 @@ func TestStartStopRandomNodes(t *testing.T) {
}
}
}

func waitForPeerEventPropagation() {
// Sleep here to ensure that Network.watchPeerEvents defer function
// has set the `node.Up() = false` before we start the node again.
//
// The same node is stopped and started again, and upon start
// watchPeerEvents is started in a goroutine. If the node is stopped
// and then very quickly started, that goroutine may be scheduled later
// then start and force `node.Up() = false` in its defer function.
// This will make this test unreliable.
time.Sleep(1 * time.Second)
}

0 comments on commit 4b2f34c

Please sign in to comment.