Skip to content

Commit a5e7bfa

Browse files
Al2Klimovoxzi
authored andcommitted
Test com.Cond#Broadcast()
1 parent 2e83eff commit a5e7bfa

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

com/cond_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

0 commit comments

Comments
 (0)