viper-app/pkg/chan_test.go

31 lines
388 B
Go
Raw Normal View History

2023-02-03 16:18:31 +08:00
package pkg
import (
"sync"
"testing"
)
func TestChan(t *testing.T) {
t.Run("close", func(t *testing.T) {
ch := NewSingleChan()
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
ch.Send()
//ch.Send()
close(ch)
tmp, ok := <-ch
t.Log("after close", tmp, ok)
wg.Done()
}()
go func() {
tmp, ok := <-ch
t.Log(tmp, ok)
wg.Done()
}()
wg.Wait()
})
}