go-zero/core/syncx/donechan_test.go

32 lines
405 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package syncx
import (
"sync"
"testing"
)
func TestDoneChanClose(t *testing.T) {
doneChan := NewDoneChan()
for i := 0; i < 5; i++ {
doneChan.Close()
}
}
func TestDoneChanDone(t *testing.T) {
var waitGroup sync.WaitGroup
doneChan := NewDoneChan()
waitGroup.Add(1)
go func() {
2021-09-29 13:09:20 +08:00
<-doneChan.Done()
waitGroup.Done()
2020-07-26 17:09:05 +08:00
}()
for i := 0; i < 5; i++ {
doneChan.Close()
}
waitGroup.Wait()
}