MCPcopy
hub / github.com/redis/go-redis / TestMaxWorkersLogic

Function TestMaxWorkersLogic

maintnotifications/config_test.go:425–476  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

423}
424
425func TestMaxWorkersLogic(t *testing.T) {
426 t.Run("AutoCalculatedMaxWorkers", func(t *testing.T) {
427 testCases := []struct {
428 poolSize int
429 expectedWorkers int
430 description string
431 }{
432 {6, 3, "Small pool: min(6/2, max(10, 6/3)) = min(3, max(10, 2)) = min(3, 10) = 3"},
433 {15, 7, "Medium pool: min(15/2, max(10, 15/3)) = min(7, max(10, 5)) = min(7, 10) = 7"},
434 {30, 10, "Large pool: min(30/2, max(10, 30/3)) = min(15, max(10, 10)) = min(15, 10) = 10"},
435 {60, 20, "Very large pool: min(60/2, max(10, 60/3)) = min(30, max(10, 20)) = min(30, 20) = 20"},
436 {120, 40, "Huge pool: min(120/2, max(10, 120/3)) = min(60, max(10, 40)) = min(60, 40) = 40"},
437 }
438
439 for _, tc := range testCases {
440 config := &Config{} // MaxWorkers = 0 (not set)
441 result := config.ApplyDefaultsWithPoolSize(tc.poolSize)
442
443 if result.MaxWorkers != tc.expectedWorkers {
444 t.Errorf("PoolSize=%d: expected MaxWorkers=%d, got %d (%s)",
445 tc.poolSize, tc.expectedWorkers, result.MaxWorkers, tc.description)
446 }
447 }
448 })
449
450 t.Run("ExplicitlySetMaxWorkers", func(t *testing.T) {
451 testCases := []struct {
452 setValue int
453 expectedWorkers int
454 description string
455 }{
456 {1, 50, "Set 1: max(poolSize/2, 1) = max(50, 1) = 50 (enforced minimum)"},
457 {5, 50, "Set 5: max(poolSize/2, 5) = max(50, 5) = 50 (enforced minimum)"},
458 {8, 50, "Set 8: max(poolSize/2, 8) = max(50, 8) = 50 (enforced minimum)"},
459 {10, 50, "Set 10: max(poolSize/2, 10) = max(50, 10) = 50 (enforced minimum)"},
460 {15, 50, "Set 15: max(poolSize/2, 15) = max(50, 15) = 50 (enforced minimum)"},
461 {60, 60, "Set 60: max(poolSize/2, 60) = max(50, 60) = 60 (respects user choice)"},
462 }
463
464 for _, tc := range testCases {
465 config := &Config{
466 MaxWorkers: tc.setValue, // Explicitly set
467 }
468 result := config.ApplyDefaultsWithPoolSize(100) // Pool size doesn't affect explicit values
469
470 if result.MaxWorkers != tc.expectedWorkers {
471 t.Errorf("Set MaxWorkers=%d: expected %d, got %d (%s)",
472 tc.setValue, tc.expectedWorkers, result.MaxWorkers, tc.description)
473 }
474 }
475 })
476}
477
478
479func TestIsPrivateIP(t *testing.T) {

Callers

nothing calls this directly

Calls 2

RunMethod · 0.45

Tested by

no test coverage detected