@@ -114,26 +114,47 @@ func TestWorkerJamDuration(t *testing.T) {
114114 v := i
115115 err = workerPool .Schedule (func () {
116116 // Nothing to do
117- time .Sleep (10 * time .Millisecond )
117+ time .Sleep (20 * time .Millisecond )
118118 t .Log (v )
119119 anyOneDone = true
120120 })
121121 assert .NoError (t , err )
122122 }
123- time .Sleep (1 * time .Millisecond )
123+ time .Sleep (3 * time .Millisecond )
124124 // BatchSize: 0, SetWorkerSizeStandBy: 3 -> 3 workers
125125 assert .Equal (t , 3 , defaultWorkerPool .workerCount )
126126 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
127130 workerPool .Schedule (func (){})
128131 workerPool .Schedule (func (){})
129132 workerPool .Schedule (func (){})
130133 time .Sleep (3 * time .Millisecond )
134+ // A new expected goroutine is generated
131135 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
132152 workerPool .Schedule (func (){})
133153 workerPool .Schedule (func (){})
134154 workerPool .Schedule (func (){})
135155 workerPool .Schedule (func (){})
136156 assert .Equal (t , false , anyOneDone )
137157 time .Sleep (1 * time .Millisecond )
158+ // A new expected goroutine is generated
138159 assert .Equal (t , 5 , defaultWorkerPool .workerCount )
139160}
0 commit comments