Commit 157cd11 1 parent a070fb5 commit 157cd11 Copy full SHA for 157cd11
File tree 2 files changed +35
-3
lines changed
2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ func NewConditionVariable(
46
46
lock : lock ,
47
47
48
48
chanLock : sync.Mutex {},
49
- channel : make ( chan struct {}, 1 ),
49
+ channel : newCVChannel ( ),
50
50
}
51
51
}
52
52
@@ -64,7 +64,7 @@ func (c *ConditionVariableImpl) Signal() {
64
64
65
65
// Broadcast wakes all goroutines waiting on this condition variable.
66
66
func (c * ConditionVariableImpl ) Broadcast () {
67
- newChannel := make ( chan struct {} )
67
+ newChannel := newCVChannel ( )
68
68
69
69
c .chanLock .Lock ()
70
70
defer c .chanLock .Unlock ()
@@ -104,3 +104,7 @@ func (c *ConditionVariableImpl) Wait(
104
104
// interrupted
105
105
}
106
106
}
107
+
108
+ func newCVChannel () chan struct {} {
109
+ return make (chan struct {}, 1 )
110
+ }
Original file line number Diff line number Diff line change 40
40
suite.Suite
41
41
42
42
lock sync.Locker
43
- cv ConditionVariable
43
+ cv * ConditionVariableImpl
44
44
}
45
45
)
46
46
@@ -67,6 +67,34 @@ func (s *conditionVariableSuite) TearDownTest() {
67
67
68
68
}
69
69
70
+ func (s * conditionVariableSuite ) TestChannelSize_New () {
71
+ s .testChannelSize (s .cv .channel )
72
+ }
73
+
74
+ func (s * conditionVariableSuite ) TestChannelSize_Broadcast () {
75
+ s .cv .Broadcast ()
76
+ s .testChannelSize (s .cv .channel )
77
+ }
78
+
79
+ func (s * conditionVariableSuite ) testChannelSize (
80
+ channel chan struct {},
81
+ ) {
82
+ // assert channel size == 1
83
+ select {
84
+ case channel <- struct {}{}:
85
+ // noop
86
+ default :
87
+ s .Fail ("conditional variable size should be 1" )
88
+ }
89
+
90
+ select {
91
+ case channel <- struct {}{}:
92
+ s .Fail ("conditional variable size should be 1" )
93
+ default :
94
+ // noop
95
+ }
96
+ }
97
+
70
98
func (s * conditionVariableSuite ) TestSignal () {
71
99
signalWaitGroup := sync.WaitGroup {}
72
100
signalWaitGroup .Add (1 )
You can’t perform that action at this time.
0 commit comments