From 45fd7503189cb6a6870f4c7e29c9ef5931181b07 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 4 Apr 2015 20:02:22 +0100 Subject: [PATCH] cosmetic: move some test helpers from test code into main code since they reach quite deeply into the data structures --- router/gossip.go | 24 ++++++++++++++++++++++++ router/gossip_test.go | 22 ---------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/router/gossip.go b/router/gossip.go index bf954bf8..4e9e060d 100644 --- a/router/gossip.go +++ b/router/gossip.go @@ -244,3 +244,27 @@ func (c *GossipChannel) relayGossipBroadcast(srcName PeerName, msg []byte) error func (c *GossipChannel) log(args ...interface{}) { log.Println(append(append([]interface{}{}, "[gossip "+c.name+"]:"), args...)...) } + +// for testing + +// FIXME this doesn't actually guarantee everything has been sent +// since a GossipSender may be in the process of sending and there is +// no easy way for us to know when that has completed. +func (router *Router) sendPendingGossip() { + for _, channel := range router.GossipChannels { + for _, sender := range channel.senders { + sender.flush() + } + } +} + +func (sender *GossipSender) flush() { + for { + select { + case pending := <-sender.cell: + sender.send(pending) + default: + return + } + } +} diff --git a/router/gossip_test.go b/router/gossip_test.go index 66622193..6ce97ebb 100644 --- a/router/gossip_test.go +++ b/router/gossip_test.go @@ -32,28 +32,6 @@ func (conn *mockChannelConnection) SendProtocolMsg(protocolMsg ProtocolMsg) { conn.dest.sendPendingGossip() } -// FIXME this doesn't actually guarantee everything has been sent -// since a GossipSender may be in the process of sending and there is -// no easy way for us to know when that has completed. -func (router *Router) sendPendingGossip() { - for _, channel := range router.GossipChannels { - for _, sender := range channel.senders { - sender.flush() - } - } -} - -func (sender *GossipSender) flush() { - for { - select { - case pending := <-sender.cell: - sender.send(pending) - default: - return - } - } -} - func (router *Router) AddTestChannelConnection(r *Router) { fromName := router.Ourself.Peer.Name toName := r.Ourself.Peer.Name