Skip to content

Commit

Permalink
close channels once no matter what
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jan 12, 2022
1 parent ce94fad commit 9927ae9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions itest/rcmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func TestResourceManagerServiceInbound(t *testing.T) {
*ready1 = make(chan struct{})
*ready2 = make(chan struct{})

var once sync.Once
var wg sync.WaitGroup
for i := 1; i < 5; i++ {
wg.Add(1)
Expand All @@ -108,7 +109,9 @@ func TestResourceManagerServiceInbound(t *testing.T) {
err := echos[i].Echo(echos[0].Host.ID(), "hello libp2p")
if err != nil {
t.Log(err)
close(*ready2)
once.Do(func() {
close(*ready2)
})
}
}(i)
}
Expand Down Expand Up @@ -178,6 +181,7 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
*ready2 = make(chan struct{})
echos[0].BeforeRead = waitForChannel(ready2)

var once sync.Once
for i := 0; i < 3; i++ {
wg.Add(1)
go func() {
Expand All @@ -186,7 +190,9 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
err := echos[2].Echo(echos[0].Host.ID(), "hello libp2p")
if err != nil {
t.Log(err)
close(*ready2)
once.Do(func() {
close(*ready2)
})
}
}()
}
Expand Down

0 comments on commit 9927ae9

Please sign in to comment.