aboutsummaryrefslogtreecommitdiffstats
path: root/core/test/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/test/utils.go')
-rw-r--r--core/test/utils.go19
1 files changed, 19 insertions, 0 deletions
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
+}