From fea8cbf92045c07b4e93d2ac0d48066cbf9797f8 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 6 Nov 2017 15:57:19 -0800 Subject: [PATCH] routing: add quit channel to mockChainView --- routing/notifications_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/routing/notifications_test.go b/routing/notifications_test.go index 961d097f7..05d859a7e 100644 --- a/routing/notifications_test.go +++ b/routing/notifications_test.go @@ -213,6 +213,8 @@ type mockChainView struct { staleBlocks chan *chainview.FilteredBlock filter map[wire.OutPoint]struct{} + + quit chan struct{} } // A compile time check to ensure mockChainView implements the @@ -224,6 +226,7 @@ func newMockChainView() *mockChainView { newBlocks: make(chan *chainview.FilteredBlock, 10), staleBlocks: make(chan *chainview.FilteredBlock, 10), filter: make(map[wire.OutPoint]struct{}), + quit: make(chan struct{}), } } @@ -244,10 +247,14 @@ func (m *mockChainView) notifyBlock(hash chainhash.Hash, height uint32, m.RLock() defer m.RUnlock() - m.newBlocks <- &chainview.FilteredBlock{ + select { + case m.newBlocks <- &chainview.FilteredBlock{ Hash: hash, Height: height, Transactions: txns, + }: + case <-m.quit: + return } } @@ -257,10 +264,14 @@ func (m *mockChainView) notifyStaleBlock(hash chainhash.Hash, height uint32, m.RLock() defer m.RUnlock() - m.staleBlocks <- &chainview.FilteredBlock{ + select { + case m.staleBlocks <- &chainview.FilteredBlock{ Hash: hash, Height: height, Transactions: txns, + }: + case <-m.quit: + return } }