@@ -263,59 +263,84 @@ func TestMaxConcurrentDialsOptions(t *testing.T) {
263263 maxConcurrentDials int
264264 expectedConcurrentDials int
265265 }{
266+ // Zero value tests - MaxConcurrentDials should be set to PoolSize
266267 {
267268 name : "zero value with default pool size" ,
268269 poolSize : 0 , // will become 10 * GOMAXPROCS in init()
269270 maxConcurrentDials : 0 ,
270- expectedConcurrentDials : 0 , // will be calculated in init()
271+ expectedConcurrentDials : 0 , // will be set to PoolSize in init()
271272 },
272273 {
273- name : "zero value with custom pool size 8" ,
274- poolSize : 8 ,
275- maxConcurrentDials : 0 ,
276- expectedConcurrentDials : 3 , // 8/4+1 = 3
277- },
278- {
279- name : "zero value with custom pool size 20" ,
280- poolSize : 20 ,
281- maxConcurrentDials : 0 ,
282- expectedConcurrentDials : 6 , // 20/4+1 = 6
274+ name : "positive value with default pool size" ,
275+ poolSize : 0 , // will become 10 * GOMAXPROCS in init()
276+ maxConcurrentDials : 5 ,
277+ expectedConcurrentDials : 5 , // should remain 5 if < calculated PoolSize
283278 },
284279 {
285- name : "zero value with pool size 1 " ,
280+ name : "zero value with minimum pool size" ,
286281 poolSize : 1 ,
287282 maxConcurrentDials : 0 ,
288- expectedConcurrentDials : 1 , // 1/4+1 = 1
283+ expectedConcurrentDials : 1 , // MaxConcurrentDials = PoolSize when 0
289284 },
290285 {
291- name : "zero value with pool size 3 " ,
292- poolSize : 3 ,
286+ name : "zero value with small pool size" ,
287+ poolSize : 5 ,
293288 maxConcurrentDials : 0 ,
294- expectedConcurrentDials : 1 , // 3/4+1 = 1
289+ expectedConcurrentDials : 5 , // MaxConcurrentDials = PoolSize when 0
295290 },
296291 {
297- name : "zero value with pool size 100 " ,
292+ name : "zero value with large pool size" ,
298293 poolSize : 100 ,
299294 maxConcurrentDials : 0 ,
300- expectedConcurrentDials : 26 , // 100/4+1 = 26
295+ expectedConcurrentDials : 100 , // MaxConcurrentDials = PoolSize when 0
301296 },
297+
298+ // Explicit positive value tests
302299 {
303- name : "explicit positive value" ,
300+ name : "explicit value within limit " ,
304301 poolSize : 10 ,
305- maxConcurrentDials : 5 ,
306- expectedConcurrentDials : 5 , // should remain unchanged
302+ maxConcurrentDials : 3 ,
303+ expectedConcurrentDials : 3 , // should remain unchanged when < PoolSize
307304 },
308305 {
309- name : "negative value unlimited" ,
306+ name : "explicit value equal to pool size" ,
307+ poolSize : 8 ,
308+ maxConcurrentDials : 8 ,
309+ expectedConcurrentDials : 8 , // should remain unchanged when = PoolSize
310+ },
311+ {
312+ name : "explicit minimum value" ,
313+ poolSize : 10 ,
314+ maxConcurrentDials : 1 ,
315+ expectedConcurrentDials : 1 , // minimum valid value
316+ },
317+
318+ // Capping tests - values exceeding PoolSize should be capped
319+ {
320+ name : "value exceeding pool size" ,
321+ poolSize : 5 ,
322+ maxConcurrentDials : 10 ,
323+ expectedConcurrentDials : 5 , // should be capped at PoolSize
324+ },
325+ {
326+ name : "large value exceeding small pool" ,
327+ poolSize : 2 ,
328+ maxConcurrentDials : 1000 ,
329+ expectedConcurrentDials : 2 , // should be capped at PoolSize
330+ },
331+
332+ // Edge cases and invalid values - negative/zero values set to PoolSize
333+ {
334+ name : "negative value gets set to pool size" ,
310335 poolSize : 10 ,
311336 maxConcurrentDials : - 1 ,
312- expectedConcurrentDials : 10 , // negative means unlimited, set to PoolSize
337+ expectedConcurrentDials : 10 , // negative values are set to PoolSize
313338 },
314339 {
315- name : "negative value unlimited with large pool" ,
316- poolSize : 50 ,
317- maxConcurrentDials : - 5 ,
318- expectedConcurrentDials : 50 , // negative means unlimited, set to PoolSize
340+ name : "large negative value gets set to pool size " ,
341+ poolSize : 3 ,
342+ maxConcurrentDials : - 100 ,
343+ expectedConcurrentDials : 3 , // negative values are set to PoolSize
319344 },
320345 }
321346
@@ -328,12 +353,14 @@ func TestMaxConcurrentDialsOptions(t *testing.T) {
328353 opts .init ()
329354
330355 if tc .expectedConcurrentDials == 0 {
331- // For default pool size case, calculate expected value
356+ // For default pool size case, set expected value based on input
332357 if tc .poolSize == 0 {
333- expectedPoolSize := opts .PoolSize // PoolSize was set by init()
334- tc .expectedConcurrentDials = expectedPoolSize / 4 + 1
335- if tc .expectedConcurrentDials > expectedPoolSize {
336- tc .expectedConcurrentDials = expectedPoolSize
358+ if tc .maxConcurrentDials == 0 {
359+ tc .expectedConcurrentDials = opts .PoolSize // MaxConcurrentDials = PoolSize when 0
360+ } else {
361+ // For positive maxConcurrentDials with default PoolSize,
362+ // it should remain unchanged if <= calculated PoolSize
363+ tc .expectedConcurrentDials = tc .maxConcurrentDials
337364 }
338365 }
339366 }
@@ -343,13 +370,13 @@ func TestMaxConcurrentDialsOptions(t *testing.T) {
343370 opts .MaxConcurrentDials , tc .expectedConcurrentDials , opts .PoolSize )
344371 }
345372
346- // Ensure MaxConcurrentDials never exceeds PoolSize
373+ // Ensure MaxConcurrentDials never exceeds PoolSize (for all inputs)
347374 if opts .MaxConcurrentDials > opts .PoolSize {
348375 t .Errorf ("MaxConcurrentDials (%v) should not exceed PoolSize (%v)" ,
349376 opts .MaxConcurrentDials , opts .PoolSize )
350377 }
351378
352- // Ensure MaxConcurrentDials is always positive
379+ // Ensure MaxConcurrentDials is always positive (for all inputs)
353380 if opts .MaxConcurrentDials <= 0 {
354381 t .Errorf ("MaxConcurrentDials should be positive, got %v" , opts .MaxConcurrentDials )
355382 }
0 commit comments