@@ -114,26 +114,47 @@ func TestWorkerJamDuration(t *testing.T) {
114
114
v := i
115
115
err = workerPool .Schedule (func () {
116
116
// Nothing to do
117
- time .Sleep (10 * time .Millisecond )
117
+ time .Sleep (20 * time .Millisecond )
118
118
t .Log (v )
119
119
anyOneDone = true
120
120
})
121
121
assert .NoError (t , err )
122
122
}
123
- time .Sleep (1 * time .Millisecond )
123
+ time .Sleep (3 * time .Millisecond )
124
124
// BatchSize: 0, SetWorkerSizeStandBy: 3 -> 3 workers
125
125
assert .Equal (t , 3 , defaultWorkerPool .workerCount )
126
126
time .Sleep (3 * time .Millisecond )
127
+ // Though there're blocking jobs, but no newest job goes into the queue
128
+ assert .Equal (t , 3 , defaultWorkerPool .workerCount )
129
+ // There're new jobs going to the queue, and all goroutines are busy
127
130
workerPool .Schedule (func (){})
128
131
workerPool .Schedule (func (){})
129
132
workerPool .Schedule (func (){})
130
133
time .Sleep (3 * time .Millisecond )
134
+ // A new expected goroutine is generated
131
135
assert .Equal (t , 4 , defaultWorkerPool .workerCount )
136
+ workerPool .Schedule (func (){})
137
+ workerPool .Schedule (func (){})
138
+ workerPool .Schedule (func (){})
139
+ time .Sleep (3 * time .Millisecond )
140
+ // Only non blocking jobs, thus keep the same amount
141
+ assert .Equal (t , 4 , defaultWorkerPool .workerCount )
142
+ // There's a blocking jobs going to the queue
143
+ workerPool .Schedule (func (){
144
+ time .Sleep (20 * time .Millisecond )
145
+ t .Log (3 )
146
+ anyOneDone = true
147
+ })
148
+ time .Sleep (3 * time .Millisecond )
149
+ // Though there're blocking jobs, but no newest job goes into the queue
150
+ assert .Equal (t , 4 , defaultWorkerPool .workerCount )
151
+ // There're new jobs going to the queue, and all goroutines are busy
132
152
workerPool .Schedule (func (){})
133
153
workerPool .Schedule (func (){})
134
154
workerPool .Schedule (func (){})
135
155
workerPool .Schedule (func (){})
136
156
assert .Equal (t , false , anyOneDone )
137
157
time .Sleep (1 * time .Millisecond )
158
+ // A new expected goroutine is generated
138
159
assert .Equal (t , 5 , defaultWorkerPool .workerCount )
139
160
}
0 commit comments