File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -43,3 +43,38 @@ func TestCond_Broadcast(t *testing.T) {
4343 require .Fail (t , "cond should be ready" )
4444 }
4545}
46+
47+ func TestCond_Close (t * testing.T ) {
48+ cond := NewCond (context .Background ())
49+ done := cond .Done ()
50+ wait := cond .Wait ()
51+
52+ require .NoError (t , cond .Close ())
53+
54+ select {
55+ case _ , ok := <- done :
56+ if ok {
57+ require .Fail (t , "existing cond-closed channel should be closed" )
58+ }
59+ case <- time .After (time .Second / 10 ):
60+ require .Fail (t , "cond should be closed" )
61+ }
62+
63+ select {
64+ case _ , ok := <- cond .Done ():
65+ if ok {
66+ require .Fail (t , "new cond-closed channel should be closed" )
67+ }
68+ case <- time .After (time .Second / 10 ):
69+ require .Fail (t , "cond should be still closed" )
70+ }
71+
72+ select {
73+ case <- wait :
74+ require .Fail (t , "cond should not be ready" )
75+ case <- time .After (time .Second / 10 ):
76+ }
77+
78+ require .Panics (t , func () { cond .Wait () }, "cond should panic on Wait after Close" )
79+ require .Panics (t , func () { cond .Broadcast () }, "cond should panic on Broadcast after Close" )
80+ }
You can’t perform that action at this time.
0 commit comments