From e25b1235d016d6c6f6d785de419a37b3ef0ad725 Mon Sep 17 00:00:00 2001 From: BurtonQin Date: Thu, 13 Feb 2020 23:02:37 +0800 Subject: [PATCH] test.Fatal() can only be used in test goroutine instead of its child --- core/blockchain_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index de23ead210..a5db2d83b4 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -993,14 +993,27 @@ func TestLogRebirth(t *testing.T) { signer = types.NewEIP155Signer(gspec.Config.ChainID) newLogCh = make(chan bool) removeLogCh = make(chan bool) + errMsgCh = make(chan string, 5) // Receive error message from validateLogEvent ) + defer func() { + n := 5 // 5 is the number of times validateLogEvent is used to create new goroutines + for i := 0; i < n; i++ { + if msg := <-errMsgCh; msg != "" { + t.Fatal(msg) + } + } + }() + // validateLogEvent checks whether the received logs number is equal with expected. validateLogEvent := func(sink interface{}, result chan bool, expect int) { chanval := reflect.ValueOf(sink) chantyp := chanval.Type() if chantyp.Kind() != reflect.Chan || chantyp.ChanDir()&reflect.RecvDir == 0 { - t.Fatalf("invalid channel, given type %v", chantyp) + errMsgCh <- fmt.Sprintf("invalid channel, given type %v", chantyp) + return + } else { + errMsgCh <- "" } cnt := 0 var recv []reflect.Value