Add a flush() function to the mock gossip router, and call it where required
This commit is contained in:
1 parent
959e5f0082
commit
c659e3448a
2 files changed
+19
-1
No files matched your search
@@ -256,13 +256,17 @@ func TestTransfer(t *testing.T) {
|
|||||||
wt.AssertTrue(t, err == nil, "Failed to get address")
|
wt.AssertTrue(t, err == nil, "Failed to get address")
|
||||||
|
|
||||||
router.GossipBroadcast(alloc2.Gossip())
|
router.GossipBroadcast(alloc2.Gossip())
|
||||||
|
router.flush()
|
||||||
router.GossipBroadcast(alloc3.Gossip())
|
router.GossipBroadcast(alloc3.Gossip())
|
||||||
|
router.flush()
|
||||||
router.removePeer(alloc2.ourName)
|
router.removePeer(alloc2.ourName)
|
||||||
router.removePeer(alloc3.ourName)
|
router.removePeer(alloc3.ourName)
|
||||||
alloc2.Stop()
|
alloc2.Stop()
|
||||||
alloc3.Stop()
|
alloc3.Stop()
|
||||||
|
router.flush()
|
||||||
wt.AssertSuccess(t, alloc1.AdminTakeoverRanges(alloc2.ourName.String()))
|
wt.AssertSuccess(t, alloc1.AdminTakeoverRanges(alloc2.ourName.String()))
|
||||||
wt.AssertSuccess(t, alloc1.AdminTakeoverRanges(alloc3.ourName.String()))
|
wt.AssertSuccess(t, alloc1.AdminTakeoverRanges(alloc3.ourName.String()))
|
||||||
|
router.flush()
|
||||||
|
|
||||||
wt.AssertEquals(t, alloc1.NumFreeAddresses(subnet), address.Offset(1022))
|
wt.AssertEquals(t, alloc1.NumFreeAddresses(subnet), address.Offset(1022))
|
||||||
|
|
||||||
|
|||||||
+15
-1
@@ -210,6 +210,9 @@ type broadcastMessage struct {
|
|||||||
type exitMessage struct {
|
type exitMessage struct {
|
||||||
exitChan chan struct{}
|
exitChan chan struct{}
|
||||||
}
|
}
|
||||||
|
type flushMessage struct {
|
||||||
|
flushChan chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
type TestGossipRouter struct {
|
type TestGossipRouter struct {
|
||||||
gossipChans map[router.PeerName]chan interface{}
|
gossipChans map[router.PeerName]chan interface{}
|
||||||
@@ -226,6 +229,14 @@ func (grouter *TestGossipRouter) GossipBroadcast(update router.GossipData) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (grouter *TestGossipRouter) flush() {
|
||||||
|
for _, gossipChan := range grouter.gossipChans {
|
||||||
|
flushChan := make(chan struct{})
|
||||||
|
gossipChan <- flushMessage{flushChan: flushChan}
|
||||||
|
<-flushChan
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (grouter *TestGossipRouter) removePeer(peer router.PeerName) {
|
func (grouter *TestGossipRouter) removePeer(peer router.PeerName) {
|
||||||
gossipChan := grouter.gossipChans[peer]
|
gossipChan := grouter.gossipChans[peer]
|
||||||
resultChan := make(chan struct{})
|
resultChan := make(chan struct{})
|
||||||
@@ -251,6 +262,9 @@ func (grouter *TestGossipRouter) connect(sender router.PeerName, gossiper router
|
|||||||
close(message.exitChan)
|
close(message.exitChan)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if message, isFlush := gossip.(flushMessage); isFlush {
|
||||||
|
close(message.flushChan)
|
||||||
|
}
|
||||||
if rand.Float32() > (1.0 - grouter.loss) {
|
if rand.Float32() > (1.0 - grouter.loss) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -305,7 +319,7 @@ func makeNetworkOfAllocators(size int, cidr string) ([]*Allocator, TestGossipRou
|
|||||||
}
|
}
|
||||||
|
|
||||||
gossipRouter.GossipBroadcast(allocs[size-1].Gossip())
|
gossipRouter.GossipBroadcast(allocs[size-1].Gossip())
|
||||||
time.Sleep(1000 * time.Millisecond)
|
gossipRouter.flush()
|
||||||
return allocs, gossipRouter, subnet
|
return allocs, gossipRouter, subnet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user