@@ -93,3 +93,47 @@ func TestScheduleWithTimeout(t *testing.T) {
93
93
err = workerPool .ScheduleWithTimeout (func () {}, 10 * time .Millisecond )
94
94
assert .Equal (t , nil , err )
95
95
}
96
+
97
+ func TestWorkerJamDuration (t * testing.T ) {
98
+ var workerPool WorkerPool
99
+ var err error
100
+ defaultWorkerPool := NewDefaultWorkerPool (fpgo .NewBufferedChannelQueue [func ()](3 , 10000 , 100 ), nil ).
101
+ SetSpawnWorkerDuration (1 * time .Millisecond / 10 ).
102
+ SetWorkerExpiryDuration (5 * time .Millisecond ).
103
+ SetWorkerJamDuration (3 * time .Millisecond ).
104
+ SetWorkerSizeMaximum (10 ).
105
+ SetWorkerSizeStandBy (3 ).
106
+ SetWorkerBatchSize (0 )
107
+ // defaultWorkerPool.PreAllocWorkerSize(5)
108
+ workerPool = defaultWorkerPool
109
+
110
+ // Test Spawn
111
+ assert .Equal (t , 0 , defaultWorkerPool .workerCount )
112
+ anyOneDone := false
113
+ for i := 0 ; i < 3 ; i ++ {
114
+ v := i
115
+ err = workerPool .Schedule (func () {
116
+ // Nothing to do
117
+ time .Sleep (10 * time .Millisecond )
118
+ t .Log (v )
119
+ anyOneDone = true
120
+ })
121
+ assert .NoError (t , err )
122
+ }
123
+ time .Sleep (1 * time .Millisecond )
124
+ // BatchSize: 0, SetWorkerSizeStandBy: 3 -> 3 workers
125
+ assert .Equal (t , 3 , defaultWorkerPool .workerCount )
126
+ time .Sleep (3 * time .Millisecond )
127
+ workerPool .Schedule (func (){})
128
+ workerPool .Schedule (func (){})
129
+ workerPool .Schedule (func (){})
130
+ time .Sleep (3 * time .Millisecond )
131
+ assert .Equal (t , 4 , defaultWorkerPool .workerCount )
132
+ workerPool .Schedule (func (){})
133
+ workerPool .Schedule (func (){})
134
+ workerPool .Schedule (func (){})
135
+ workerPool .Schedule (func (){})
136
+ assert .Equal (t , false , anyOneDone )
137
+ time .Sleep (1 * time .Millisecond )
138
+ assert .Equal (t , 5 , defaultWorkerPool .workerCount )
139
+ }
0 commit comments