From 24c0cecbbf7ba84754ccc02d37c9540ce317976c Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Fri, 12 Apr 2019 11:35:37 +0800 Subject: core: add report bad peer interface to network (#559) --- core/utils/utils.go | 2 +- core/utils/utils_test.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'core/utils') diff --git a/core/utils/utils.go b/core/utils/utils.go index 1a372c7..dc29bdf 100644 --- a/core/utils/utils.go +++ b/core/utils/utils.go @@ -105,7 +105,7 @@ func VerifyDKGComplaint( // channel of a network module. An context is required to stop the go routine // automatically. An optinal message handler could be provided. func LaunchDummyReceiver( - ctx context.Context, recv <-chan interface{}, handler func(interface{})) ( + ctx context.Context, recv <-chan types.Msg, handler func(types.Msg)) ( context.CancelFunc, <-chan struct{}) { var ( dummyCtx, dummyCancel = context.WithCancel(ctx) diff --git a/core/utils/utils_test.go b/core/utils/utils_test.go index c3afea9..c6f8543 100644 --- a/core/utils/utils_test.go +++ b/core/utils/utils_test.go @@ -121,14 +121,16 @@ func (s *UtilsTestSuite) TestDummyReceiver() { for i := 0; i < msgCount; i++ { fakeMsgs = append(fakeMsgs, i) } - launchDummySender := func(msgs []int, inputChan chan<- interface{}) { + launchDummySender := func(msgs []int, inputChan chan<- types.Msg) { finished := make(chan struct{}, 1) go func() { defer func() { finished <- struct{}{} }() for _, v := range msgs { - inputChan <- v + inputChan <- types.Msg{ + Payload: v, + } } }() select { @@ -137,17 +139,17 @@ func (s *UtilsTestSuite) TestDummyReceiver() { s.Require().FailNow("unable to deliver all messages in time") } } - checkBuffer := func(sent []int, buff []interface{}) { + checkBuffer := func(sent []int, buff []types.Msg) { s.Require().Len(buff, len(sent)) for i := range sent { - s.Require().Equal(sent[i], buff[i].(int)) + s.Require().Equal(sent[i], buff[i].Payload.(int)) } } // Basic scenario: a dummy receiver with caching enabled. - recv := make(chan interface{}) - buff := []interface{}{} + recv := make(chan types.Msg) + buff := []types.Msg{} cancel, finished := LaunchDummyReceiver( - context.Background(), recv, func(msg interface{}) { + context.Background(), recv, func(msg types.Msg) { buff = append(buff, msg) }) launchDummySender(fakeMsgs, recv) -- cgit v1.2.3