From 33ffd6e3422e443db66082d32ba343a7822f0d76 Mon Sep 17 00:00:00 2001 From: 0xcb9ff9 <111933059+0xcb9ff9@users.noreply.github.com> Date: Mon, 13 Feb 2023 11:57:01 +0800 Subject: [PATCH] [test] fix unit test (#298) # Description fix random ci test failed ``` panic: send on closed channel goroutine 422 [running]: github.com/dogechain-lab/dogechain/protocol.(*syncPeerClient).handleStatusUpdate(0xc000160cf0, {0xfb7720, 0xc0025efc80}, {0xc000b6ca80, 0xc000bdf701}) /home/runner/work/dogechain/dogechain/protocol/client.go:225 +0x3ec ``` # Changes include - [x] Bugfix (non-breaking change that solves an issue) # Testing - [x] I have tested this code with the official test suite --- protocol/client_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/protocol/client_test.go b/protocol/client_test.go index 3fd6dea818..ac885d429a 100644 --- a/protocol/client_test.go +++ b/protocol/client_test.go @@ -352,9 +352,14 @@ func TestPeerConnectionUpdateEventCh(t *testing.T) { go func() { defer wgForConnectingStatus.Done() + wgForGossip.Wait() for status := range client.GetPeerStatusUpdateCh() { newStatuses = append(newStatuses, status) + + if len(newStatuses) > 0 { + break + } } }() @@ -377,9 +382,6 @@ func TestPeerConnectionUpdateEventCh(t *testing.T) { // wait until 2 messages are propagated wgForGossip.Wait() - // close to terminate goroutine - close(client.peerStatusUpdateCh) - // wait until collecting routine is done wgForConnectingStatus.Wait()