@@ -118,74 +118,74 @@ func TestApplyDefaults(t *testing.T) {
118118 }
119119
120120 // HandoffQueueSize should be auto-calculated with hybrid scaling
121- workerBasedSize := result .MaxWorkers * 8
121+ workerBasedSize := result .MaxWorkers * 20
122122 poolSize := 100 // Default pool size used in ApplyDefaults
123- poolBasedSize := util . Max ( 50 , poolSize / 2 )
123+ poolBasedSize := poolSize
124124 expectedQueueSize := util .Max (workerBasedSize , poolBasedSize )
125- expectedQueueSize = util .Min (expectedQueueSize , poolSize * 2 ) // Cap by 2x pool size
125+ expectedQueueSize = util .Min (expectedQueueSize , poolSize * 5 ) // Cap by 5x pool size
126126 if result .HandoffQueueSize != expectedQueueSize {
127- t .Errorf ("Expected HandoffQueueSize to be %d (max(8 *MaxWorkers=%d, max(50, poolSize/2 =%d)) capped by 2 *poolSize=%d), got %d" ,
128- expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 2 , result .HandoffQueueSize )
127+ t .Errorf ("Expected HandoffQueueSize to be %d (max(20 *MaxWorkers=%d, poolSize=%d) capped by 5 *poolSize=%d), got %d" ,
128+ expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 5 , result .HandoffQueueSize )
129129 }
130130 })
131131
132132 t .Run ("PartialConfig" , func (t * testing.T ) {
133133 config := & Config {
134- MaxWorkers : 12 , // Set this field explicitly
134+ MaxWorkers : 60 , // Set this field explicitly (> poolSize/2 = 50)
135135 // Leave other fields as zero values
136136 }
137137
138138 result := config .ApplyDefaultsWithPoolSize (100 ) // Use explicit pool size for testing
139139
140- // Should keep the explicitly set values
141- if result .MaxWorkers != 12 {
142- t .Errorf ("Expected MaxWorkers to be 12 (explicitly set), got %d" , result .MaxWorkers )
140+ // Should keep the explicitly set values when > poolSize/2
141+ if result .MaxWorkers != 60 {
142+ t .Errorf ("Expected MaxWorkers to be 60 (explicitly set), got %d" , result .MaxWorkers )
143143 }
144144
145145 // Should apply default for unset fields (auto-calculated queue size with hybrid scaling)
146- workerBasedSize := result .MaxWorkers * 8
146+ workerBasedSize := result .MaxWorkers * 20
147147 poolSize := 100 // Default pool size used in ApplyDefaults
148- poolBasedSize := util . Max ( 50 , poolSize / 2 )
148+ poolBasedSize := poolSize
149149 expectedQueueSize := util .Max (workerBasedSize , poolBasedSize )
150- expectedQueueSize = util .Min (expectedQueueSize , poolSize * 2 ) // Cap by 2x pool size
150+ expectedQueueSize = util .Min (expectedQueueSize , poolSize * 5 ) // Cap by 5x pool size
151151 if result .HandoffQueueSize != expectedQueueSize {
152- t .Errorf ("Expected HandoffQueueSize to be %d (max(8 *MaxWorkers=%d, max(50, poolSize/2 =%d)) capped by 2 *poolSize=%d), got %d" ,
153- expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 2 , result .HandoffQueueSize )
152+ t .Errorf ("Expected HandoffQueueSize to be %d (max(20 *MaxWorkers=%d, poolSize=%d) capped by 5 *poolSize=%d), got %d" ,
153+ expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 5 , result .HandoffQueueSize )
154154 }
155155
156- // Test explicit queue size capping by 2x pool size
156+ // Test explicit queue size capping by 5x pool size
157157 configWithLargeQueue := & Config {
158158 MaxWorkers : 5 ,
159- HandoffQueueSize : 1000 , // Much larger than 2x pool size
159+ HandoffQueueSize : 1000 , // Much larger than 5x pool size
160160 }
161161
162162 resultCapped := configWithLargeQueue .ApplyDefaultsWithPoolSize (20 ) // Small pool size
163- expectedCap := 20 * 2 // 2x pool size = 40
163+ expectedCap := 20 * 5 // 5x pool size = 100
164164 if resultCapped .HandoffQueueSize != expectedCap {
165- t .Errorf ("Expected HandoffQueueSize to be capped by 2x pool size (%d), got %d" , expectedCap , resultCapped .HandoffQueueSize )
165+ t .Errorf ("Expected HandoffQueueSize to be capped by 5x pool size (%d), got %d" , expectedCap , resultCapped .HandoffQueueSize )
166166 }
167167
168168 // Test explicit queue size minimum enforcement
169169 configWithSmallQueue := & Config {
170170 MaxWorkers : 5 ,
171- HandoffQueueSize : 10 , // Below minimum of 50
171+ HandoffQueueSize : 10 , // Below minimum of 200
172172 }
173173
174174 resultMinimum := configWithSmallQueue .ApplyDefaultsWithPoolSize (100 ) // Large pool size
175- if resultMinimum .HandoffQueueSize != 50 {
176- t .Errorf ("Expected HandoffQueueSize to be enforced minimum (50 ), got %d" , resultMinimum .HandoffQueueSize )
175+ if resultMinimum .HandoffQueueSize != 200 {
176+ t .Errorf ("Expected HandoffQueueSize to be enforced minimum (200 ), got %d" , resultMinimum .HandoffQueueSize )
177177 }
178178
179- // Test that large explicit values are capped by 2x pool size
179+ // Test that large explicit values are capped by 5x pool size
180180 configWithVeryLargeQueue := & Config {
181181 MaxWorkers : 5 ,
182- HandoffQueueSize : 500 , // Much larger than 2x pool size
182+ HandoffQueueSize : 1000 , // Much larger than 5x pool size
183183 }
184184
185185 resultVeryLarge := configWithVeryLargeQueue .ApplyDefaultsWithPoolSize (100 ) // Pool size 100
186- expectedVeryLargeCap := 100 * 2 // 2x pool size = 200
186+ expectedVeryLargeCap := 100 * 5 // 5x pool size = 500
187187 if resultVeryLarge .HandoffQueueSize != expectedVeryLargeCap {
188- t .Errorf ("Expected very large HandoffQueueSize to be capped by 2x pool size (%d), got %d" , expectedVeryLargeCap , resultVeryLarge .HandoffQueueSize )
188+ t .Errorf ("Expected very large HandoffQueueSize to be capped by 5x pool size (%d), got %d" , expectedVeryLargeCap , resultVeryLarge .HandoffQueueSize )
189189 }
190190
191191 if result .RelaxedTimeout != 10 * time .Second {
@@ -213,14 +213,14 @@ func TestApplyDefaults(t *testing.T) {
213213 }
214214
215215 // HandoffQueueSize should be auto-calculated with hybrid scaling
216- workerBasedSize := result .MaxWorkers * 8
216+ workerBasedSize := result .MaxWorkers * 20
217217 poolSize := 100 // Default pool size used in ApplyDefaults
218- poolBasedSize := util . Max ( 50 , poolSize / 2 )
218+ poolBasedSize := poolSize
219219 expectedQueueSize := util .Max (workerBasedSize , poolBasedSize )
220- expectedQueueSize = util .Min (expectedQueueSize , poolSize * 2 ) // Cap by 2x pool size
220+ expectedQueueSize = util .Min (expectedQueueSize , poolSize * 5 ) // Cap by 5x pool size
221221 if result .HandoffQueueSize != expectedQueueSize {
222- t .Errorf ("Expected HandoffQueueSize to be %d (max(8 *MaxWorkers=%d, max(50, poolSize/2 =%d)) capped by 2 *poolSize=%d), got %d" ,
223- expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 2 , result .HandoffQueueSize )
222+ t .Errorf ("Expected HandoffQueueSize to be %d (max(20 *MaxWorkers=%d, poolSize=%d) capped by 5 *poolSize=%d), got %d" ,
223+ expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 5 , result .HandoffQueueSize )
224224 }
225225
226226 if result .RelaxedTimeout != 10 * time .Second {
@@ -316,29 +316,29 @@ func TestIntegrationWithApplyDefaults(t *testing.T) {
316316 // and applying defaults manually
317317 expectedConfig := partialConfig .ApplyDefaultsWithPoolSize (100 ) // Use explicit pool size for testing
318318
319- // Should preserve custom values (when >= 10 )
320- if expectedConfig .MaxWorkers != 15 {
321- t .Errorf ("Expected MaxWorkers to be 15 , got %d" , expectedConfig .MaxWorkers )
319+ // Should preserve custom values (when >= poolSize/2 )
320+ if expectedConfig .MaxWorkers != 50 { // max(poolSize/2, 15) = max(50, 15) = 50
321+ t .Errorf ("Expected MaxWorkers to be 50 , got %d" , expectedConfig .MaxWorkers )
322322 }
323323
324324 if expectedConfig .LogLevel != 2 {
325325 t .Errorf ("Expected LogLevel to be 2, got %d" , expectedConfig .LogLevel )
326326 }
327327
328328 // Should apply defaults for missing fields (auto-calculated queue size with hybrid scaling)
329- workerBasedSize := expectedConfig .MaxWorkers * 8
329+ workerBasedSize := expectedConfig .MaxWorkers * 20
330330 poolSize := 100 // Default pool size used in ApplyDefaults
331- poolBasedSize := util . Max ( 50 , poolSize / 2 )
331+ poolBasedSize := poolSize
332332 expectedQueueSize := util .Max (workerBasedSize , poolBasedSize )
333- expectedQueueSize = util .Min (expectedQueueSize , poolSize * 2 ) // Cap by 2x pool size
333+ expectedQueueSize = util .Min (expectedQueueSize , poolSize * 5 ) // Cap by 5x pool size
334334 if expectedConfig .HandoffQueueSize != expectedQueueSize {
335- t .Errorf ("Expected HandoffQueueSize to be %d (max(8 *MaxWorkers=%d, max(50, poolSize/2 =%d)) capped by 2 *poolSize=%d), got %d" ,
336- expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 2 , expectedConfig .HandoffQueueSize )
335+ t .Errorf ("Expected HandoffQueueSize to be %d (max(20 *MaxWorkers=%d, poolSize=%d) capped by 5 *poolSize=%d), got %d" ,
336+ expectedQueueSize , workerBasedSize , poolBasedSize , poolSize * 5 , expectedConfig .HandoffQueueSize )
337337 }
338338
339- // Test that queue size is always capped by 2x pool size
340- if expectedConfig .HandoffQueueSize > poolSize * 2 {
341- t .Errorf ("HandoffQueueSize (%d) should never exceed 2x pool size (%d)" ,
339+ // Test that queue size is always capped by 5x pool size
340+ if expectedConfig .HandoffQueueSize > poolSize * 5 {
341+ t .Errorf ("HandoffQueueSize (%d) should never exceed 5x pool size (%d)" ,
342342 expectedConfig .HandoffQueueSize , poolSize * 2 )
343343 }
344344
@@ -413,11 +413,11 @@ func TestMaxWorkersLogic(t *testing.T) {
413413 expectedWorkers int
414414 description string
415415 }{
416- {6 , 2 , "Small pool: min(10, 6/3) = min(10, 2) = 2 " },
417- {15 , 5 , "Medium pool: min(10, 15/3) = min(10, 5) = 5 " },
418- {30 , 10 , "Large pool: min(10, 30/3) = min(10 , 10) = 10" },
419- {60 , 10 , "Very large pool: min(10, 60/3) = min(10, 20) = 10 " },
420- {120 , 10 , "Huge pool: min(10, 120/3) = min(10, 40) = 10 " },
416+ {6 , 3 , "Small pool: min(6/2, max( 10, 6/3)) = min(3, max( 10, 2)) = min(3, 10) = 3 " },
417+ {15 , 7 , "Medium pool: min(15/2, max( 10, 15/3)) = min(7, max( 10, 5)) = min(7, 10) = 7 " },
418+ {30 , 10 , "Large pool: min(30/2, max( 10, 30/3)) = min(15, max(10, 10)) = min(15 , 10) = 10" },
419+ {60 , 20 , "Very large pool: min(60/2, max( 10, 60/3)) = min(30, max( 10, 20)) = min(30, 20) = 20 " },
420+ {120 , 40 , "Huge pool: min(120/2, max( 10, 120/3)) = min(60, max( 10, 40)) = min(60, 40) = 40 " },
421421 }
422422
423423 for _ , tc := range testCases {
@@ -437,12 +437,12 @@ func TestMaxWorkersLogic(t *testing.T) {
437437 expectedWorkers int
438438 description string
439439 }{
440- {1 , 10 , "Set 1: max(10 , 1) = 10 (enforced minimum)" },
441- {5 , 10 , "Set 5: max(10 , 5) = 10 (enforced minimum)" },
442- {8 , 10 , "Set 8: max(10 , 8) = 10 (enforced minimum)" },
443- {10 , 10 , "Set 10: max(10 , 10) = 10 (exact minimum)" },
444- {15 , 15 , "Set 15: max(10 , 15) = 15 (respects user choice )" },
445- {20 , 20 , "Set 20 : max(10, 20 ) = 20 (respects user choice)" },
440+ {1 , 50 , "Set 1: max(poolSize/2 , 1) = max(50, 1) = 50 (enforced minimum)" },
441+ {5 , 50 , "Set 5: max(poolSize/2 , 5) = max(50, 5) = 50 (enforced minimum)" },
442+ {8 , 50 , "Set 8: max(poolSize/2 , 8) = max(50, 8) = 50 (enforced minimum)" },
443+ {10 , 50 , "Set 10: max(poolSize/2 , 10) = max(50, 10) = 50 (enforced minimum)" },
444+ {15 , 50 , "Set 15: max(poolSize/2 , 15) = max(50, 15) = 50 (enforced minimum )" },
445+ {60 , 60 , "Set 60 : max(poolSize/2, 60 ) = max(50, 60) = 60 (respects user choice)" },
446446 }
447447
448448 for _ , tc := range testCases {
0 commit comments