@@ -116,13 +116,15 @@ func TestApplyDefaults(t *testing.T) {
116116 t .Errorf ("Expected MaxWorkers to be > 0 after applying defaults, got %d" , result .MaxWorkers )
117117 }
118118
119- // HandoffQueueSize should be auto-calculated (10 * MaxWorkers, capped by pool size)
120- workerBasedSize := result .MaxWorkers * 10
119+ // HandoffQueueSize should be auto-calculated with hybrid scaling
120+ workerBasedSize := result .MaxWorkers * 8
121121 poolSize := 100 // Default pool size used in ApplyDefaults
122- expectedQueueSize := util .Min (workerBasedSize , poolSize )
122+ poolBasedSize := util .Max (50 , poolSize / 2 )
123+ expectedQueueSize := util .Max (workerBasedSize , poolBasedSize )
124+ expectedQueueSize = util .Min (expectedQueueSize , poolSize * 2 ) // Cap by 2x pool size
123125 if result .HandoffQueueSize != expectedQueueSize {
124- t .Errorf ("Expected HandoffQueueSize to be %d (util.Min(10 *MaxWorkers=%d, poolSize=%d)), got %d" ,
125- expectedQueueSize , workerBasedSize , poolSize , result .HandoffQueueSize )
126+ t .Errorf ("Expected HandoffQueueSize to be %d (max(8 *MaxWorkers=%d, max(50, poolSize/2 =%d)) capped by 2*poolSize=%d ), got %d" ,
127+ expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 2 , result .HandoffQueueSize )
126128 }
127129 })
128130
@@ -139,24 +141,50 @@ func TestApplyDefaults(t *testing.T) {
139141 t .Errorf ("Expected MaxWorkers to be 12 (explicitly set), got %d" , result .MaxWorkers )
140142 }
141143
142- // Should apply default for unset fields (auto-calculated queue size, capped by pool size )
143- workerBasedSize := result .MaxWorkers * 10
144+ // Should apply default for unset fields (auto-calculated queue size with hybrid scaling )
145+ workerBasedSize := result .MaxWorkers * 8
144146 poolSize := 100 // Default pool size used in ApplyDefaults
145- expectedQueueSize := util .Min (workerBasedSize , poolSize )
147+ poolBasedSize := util .Max (50 , poolSize / 2 )
148+ expectedQueueSize := util .Max (workerBasedSize , poolBasedSize )
149+ expectedQueueSize = util .Min (expectedQueueSize , poolSize * 2 ) // Cap by 2x pool size
146150 if result .HandoffQueueSize != expectedQueueSize {
147- t .Errorf ("Expected HandoffQueueSize to be %d (util.Min(10 *MaxWorkers=%d, poolSize=%d)), got %d" ,
148- expectedQueueSize , workerBasedSize , poolSize , result .HandoffQueueSize )
151+ t .Errorf ("Expected HandoffQueueSize to be %d (max(8 *MaxWorkers=%d, max(50, poolSize/2 =%d)) capped by 2*poolSize=%d ), got %d" ,
152+ expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 2 , result .HandoffQueueSize )
149153 }
150154
151- // Test explicit queue size capping by pool size
155+ // Test explicit queue size capping by 2x pool size
152156 configWithLargeQueue := & Config {
153157 MaxWorkers : 5 ,
154- HandoffQueueSize : 1000 , // Much larger than pool size
158+ HandoffQueueSize : 1000 , // Much larger than 2x pool size
155159 }
156160
157161 resultCapped := configWithLargeQueue .ApplyDefaultsWithPoolSize (20 ) // Small pool size
158- if resultCapped .HandoffQueueSize != 20 {
159- t .Errorf ("Expected HandoffQueueSize to be capped by pool size (20), got %d" , resultCapped .HandoffQueueSize )
162+ expectedCap := 20 * 2 // 2x pool size = 40
163+ if resultCapped .HandoffQueueSize != expectedCap {
164+ t .Errorf ("Expected HandoffQueueSize to be capped by 2x pool size (%d), got %d" , expectedCap , resultCapped .HandoffQueueSize )
165+ }
166+
167+ // Test explicit queue size minimum enforcement
168+ configWithSmallQueue := & Config {
169+ MaxWorkers : 5 ,
170+ HandoffQueueSize : 10 , // Below minimum of 50
171+ }
172+
173+ resultMinimum := configWithSmallQueue .ApplyDefaultsWithPoolSize (100 ) // Large pool size
174+ if resultMinimum .HandoffQueueSize != 50 {
175+ t .Errorf ("Expected HandoffQueueSize to be enforced minimum (50), got %d" , resultMinimum .HandoffQueueSize )
176+ }
177+
178+ // Test that large explicit values are capped by 2x pool size
179+ configWithVeryLargeQueue := & Config {
180+ MaxWorkers : 5 ,
181+ HandoffQueueSize : 500 , // Much larger than 2x pool size
182+ }
183+
184+ resultVeryLarge := configWithVeryLargeQueue .ApplyDefaultsWithPoolSize (100 ) // Pool size 100
185+ expectedVeryLargeCap := 100 * 2 // 2x pool size = 200
186+ if resultVeryLarge .HandoffQueueSize != expectedVeryLargeCap {
187+ t .Errorf ("Expected very large HandoffQueueSize to be capped by 2x pool size (%d), got %d" , expectedVeryLargeCap , resultVeryLarge .HandoffQueueSize )
160188 }
161189
162190 if result .RelaxedTimeout != 10 * time .Second {
@@ -183,13 +211,15 @@ func TestApplyDefaults(t *testing.T) {
183211 t .Errorf ("Expected MaxWorkers to be > 0 (auto-calculated), got %d" , result .MaxWorkers )
184212 }
185213
186- // HandoffQueueSize should be auto-calculated (10 * MaxWorkers, capped by pool size)
187- workerBasedSize := result .MaxWorkers * 10
214+ // HandoffQueueSize should be auto-calculated with hybrid scaling
215+ workerBasedSize := result .MaxWorkers * 8
188216 poolSize := 100 // Default pool size used in ApplyDefaults
189- expectedQueueSize := util .Min (workerBasedSize , poolSize )
217+ poolBasedSize := util .Max (50 , poolSize / 2 )
218+ expectedQueueSize := util .Max (workerBasedSize , poolBasedSize )
219+ expectedQueueSize = util .Min (expectedQueueSize , poolSize * 2 ) // Cap by 2x pool size
190220 if result .HandoffQueueSize != expectedQueueSize {
191- t .Errorf ("Expected HandoffQueueSize to be %d (util.Min(10 *MaxWorkers=%d, poolSize=%d)), got %d" ,
192- expectedQueueSize , workerBasedSize , poolSize , result .HandoffQueueSize )
221+ t .Errorf ("Expected HandoffQueueSize to be %d (max(8 *MaxWorkers=%d, max(50, poolSize/2 =%d)) capped by 2*poolSize=%d ), got %d" ,
222+ expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 2 , result .HandoffQueueSize )
193223 }
194224
195225 if result .RelaxedTimeout != 10 * time .Second {
@@ -294,19 +324,21 @@ func TestIntegrationWithApplyDefaults(t *testing.T) {
294324 t .Errorf ("Expected LogLevel to be 2, got %d" , expectedConfig .LogLevel )
295325 }
296326
297- // Should apply defaults for missing fields (auto-calculated queue size, capped by pool size )
298- workerBasedSize := expectedConfig .MaxWorkers * 10
327+ // Should apply defaults for missing fields (auto-calculated queue size with hybrid scaling )
328+ workerBasedSize := expectedConfig .MaxWorkers * 8
299329 poolSize := 100 // Default pool size used in ApplyDefaults
300- expectedQueueSize := util .Min (workerBasedSize , poolSize )
330+ poolBasedSize := util .Max (50 , poolSize / 2 )
331+ expectedQueueSize := util .Max (workerBasedSize , poolBasedSize )
332+ expectedQueueSize = util .Min (expectedQueueSize , poolSize * 2 ) // Cap by 2x pool size
301333 if expectedConfig .HandoffQueueSize != expectedQueueSize {
302- t .Errorf ("Expected HandoffQueueSize to be %d (util.Min(10 *MaxWorkers=%d, poolSize=%d)), got %d" ,
303- expectedQueueSize , workerBasedSize , poolSize , expectedConfig .HandoffQueueSize )
334+ t .Errorf ("Expected HandoffQueueSize to be %d (max(8 *MaxWorkers=%d, max(50, poolSize/2 =%d)) capped by 2*poolSize=%d ), got %d" ,
335+ expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 2 , expectedConfig .HandoffQueueSize )
304336 }
305337
306- // Test that queue size is always capped by pool size
307- if expectedConfig .HandoffQueueSize > poolSize {
308- t .Errorf ("HandoffQueueSize (%d) should never exceed pool size (%d)" ,
309- expectedConfig .HandoffQueueSize , poolSize )
338+ // Test that queue size is always capped by 2x pool size
339+ if expectedConfig .HandoffQueueSize > poolSize * 2 {
340+ t .Errorf ("HandoffQueueSize (%d) should never exceed 2x pool size (%d)" ,
341+ expectedConfig .HandoffQueueSize , poolSize * 2 )
310342 }
311343
312344 if expectedConfig .RelaxedTimeout != 10 * time .Second {
0 commit comments