From cdf2f43432d00d1145721ae29cac48956c7b23eb Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 6 Nov 2017 15:58:52 -0800 Subject: [PATCH] routing: add Reset() method to mockChainView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we add a Reset() method to the mockChainView struct. With this new method tests are able to fully simulate a restart of the ChannelRouter. This is necessary as the FilteredChainView instances are assumed to be stateless, and don’t write their state to disk before a restart. --- routing/notifications_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/routing/notifications_test.go b/routing/notifications_test.go index 05d859a7..47efe342 100644 --- a/routing/notifications_test.go +++ b/routing/notifications_test.go @@ -212,6 +212,8 @@ type mockChainView struct { newBlocks chan *chainview.FilteredBlock staleBlocks chan *chainview.FilteredBlock + chain lnwallet.BlockChainIO + filter map[wire.OutPoint]struct{} quit chan struct{} @@ -221,8 +223,9 @@ type mockChainView struct { // chainview.FilteredChainView. var _ chainview.FilteredChainView = (*mockChainView)(nil) -func newMockChainView() *mockChainView { +func newMockChainView(chain lnwallet.BlockChainIO) *mockChainView { return &mockChainView{ + chain: chain, newBlocks: make(chan *chainview.FilteredBlock, 10), staleBlocks: make(chan *chainview.FilteredBlock, 10), filter: make(map[wire.OutPoint]struct{}), @@ -230,6 +233,13 @@ func newMockChainView() *mockChainView { } } +func (m *mockChainView) Reset() { + m.filter = make(map[wire.OutPoint]struct{}) + m.quit = make(chan struct{}) + m.newBlocks = make(chan *chainview.FilteredBlock, 10) + m.staleBlocks = make(chan *chainview.FilteredBlock, 10) +} + func (m *mockChainView) UpdateFilter(ops []wire.OutPoint, updateHeight uint32) error { m.Lock() defer m.Unlock() @@ -316,6 +326,7 @@ func (m *mockChainView) Start() error { } func (m *mockChainView) Stop() error { + close(m.quit) return nil }