From 39c02fe0f7c81491ea897fafcf32595d280bbdbe Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Wed, 26 Dec 2018 15:23:54 +0800 Subject: core: fix stuffs (#383) * Merge core.Consensus constructors * Downgrade severity of logs * Refine logic to add blocks from pool to lattice * Add test.LaunchDummyReceiver --- core/test/utils.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'core/test') diff --git a/core/test/utils.go b/core/test/utils.go index 84c90a9..8a14ebf 100644 --- a/core/test/utils.go +++ b/core/test/utils.go @@ -18,6 +18,7 @@ package test import ( + "context" "errors" "fmt" "math" @@ -225,3 +226,21 @@ func VerifyDB(db db.Database) error { } return nil } + +// LaunchDummyReceiver launches a go routine to receive and drop messages from +// a network module. An optional context could be passed to stop the go routine. +func LaunchDummyReceiver( + ctx context.Context, networkModule *Network) context.CancelFunc { + dummyCtx, dummyCancel := context.WithCancel(ctx) + go func() { + loop: + for { + select { + case <-dummyCtx.Done(): + break loop + case <-networkModule.ReceiveChan(): + } + } + }() + return dummyCancel +} -- cgit