Skip to content

Commit c5f1d4b

Browse files
Al2Klimovoxzi
authored andcommitted
Test com.Cond#Close()
1 parent a5e7bfa commit c5f1d4b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

com/cond_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)