File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ package com
2+
3+ import (
4+ "context"
5+ "github.com/stretchr/testify/require"
6+ "testing"
7+ "time"
8+ )
9+
10+ func TestCond_Broadcast (t * testing.T ) {
11+ cond := NewCond (context .Background ())
12+ defer func () { _ = cond .Close () }()
13+
14+ done := cond .Done ()
15+ wait := cond .Wait ()
16+
17+ select {
18+ case <- done :
19+ require .Fail (t , "cond should not be closed, yet" )
20+ case <- wait :
21+ require .Fail (t , "cond should not be ready, yet" )
22+ case <- time .After (time .Second / 10 ):
23+ }
24+
25+ cond .Broadcast ()
26+
27+ select {
28+ case <- done :
29+ require .Fail (t , "cond should still not be closed" )
30+ case <- cond .Done ():
31+ require .Fail (t , "cond should not be closed for round 2, yet" )
32+ case <- cond .Wait ():
33+ require .Fail (t , "cond should not be ready for round 2" )
34+ case <- time .After (time .Second / 10 ):
35+ }
36+
37+ select {
38+ case _ , ok := <- wait :
39+ if ok {
40+ require .Fail (t , "cond ready channel should be closed" )
41+ }
42+ case <- time .After (time .Second / 10 ):
43+ require .Fail (t , "cond should be ready" )
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments