(t *testing.T)
| 115 | } |
| 116 | |
| 117 | func TestApplyDefaults(t *testing.T) { |
| 118 | t.Run("NilConfig", func(t *testing.T) { |
| 119 | var config *Config |
| 120 | result := config.ApplyDefaultsWithPoolSize(100) // Use explicit pool size for testing |
| 121 | |
| 122 | // With nil config, should get default config with auto-calculated workers |
| 123 | if result.MaxWorkers <= 0 { |
| 124 | t.Errorf("Expected MaxWorkers to be > 0 after applying defaults, got %d", result.MaxWorkers) |
| 125 | } |
| 126 | |
| 127 | // HandoffQueueSize should be auto-calculated with hybrid scaling |
| 128 | workerBasedSize := result.MaxWorkers * 20 |
| 129 | poolSize := 100 // Default pool size used in ApplyDefaults |
| 130 | poolBasedSize := poolSize |
| 131 | expectedQueueSize := max(workerBasedSize, poolBasedSize) |
| 132 | expectedQueueSize = min(expectedQueueSize, poolSize*5) // Cap by 5x pool size |
| 133 | if result.HandoffQueueSize != expectedQueueSize { |
| 134 | t.Errorf("Expected HandoffQueueSize to be %d (max(20*MaxWorkers=%d, poolSize=%d) capped by 5*poolSize=%d), got %d", |
| 135 | expectedQueueSize, workerBasedSize, poolBasedSize, poolSize*5, result.HandoffQueueSize) |
| 136 | } |
| 137 | }) |
| 138 | |
| 139 | t.Run("PartialConfig", func(t *testing.T) { |
| 140 | config := &Config{ |
| 141 | MaxWorkers: 60, // Set this field explicitly (> poolSize/2 = 50) |
| 142 | // Leave other fields as zero values |
| 143 | } |
| 144 | |
| 145 | result := config.ApplyDefaultsWithPoolSize(100) // Use explicit pool size for testing |
| 146 | |
| 147 | // Should keep the explicitly set values when > poolSize/2 |
| 148 | if result.MaxWorkers != 60 { |
| 149 | t.Errorf("Expected MaxWorkers to be 60 (explicitly set), got %d", result.MaxWorkers) |
| 150 | } |
| 151 | |
| 152 | // Should apply default for unset fields (auto-calculated queue size with hybrid scaling) |
| 153 | workerBasedSize := result.MaxWorkers * 20 |
| 154 | poolSize := 100 // Default pool size used in ApplyDefaults |
| 155 | poolBasedSize := poolSize |
| 156 | expectedQueueSize := max(workerBasedSize, poolBasedSize) |
| 157 | expectedQueueSize = min(expectedQueueSize, poolSize*5) // Cap by 5x pool size |
| 158 | if result.HandoffQueueSize != expectedQueueSize { |
| 159 | t.Errorf("Expected HandoffQueueSize to be %d (max(20*MaxWorkers=%d, poolSize=%d) capped by 5*poolSize=%d), got %d", |
| 160 | expectedQueueSize, workerBasedSize, poolBasedSize, poolSize*5, result.HandoffQueueSize) |
| 161 | } |
| 162 | |
| 163 | // Test explicit queue size capping by 5x pool size |
| 164 | configWithLargeQueue := &Config{ |
| 165 | MaxWorkers: 5, |
| 166 | HandoffQueueSize: 1000, // Much larger than 5x pool size |
| 167 | } |
| 168 | |
| 169 | resultCapped := configWithLargeQueue.ApplyDefaultsWithPoolSize(20) // Small pool size |
| 170 | expectedCap := 20 * 5 // 5x pool size = 100 |
| 171 | if resultCapped.HandoffQueueSize != expectedCap { |
| 172 | t.Errorf("Expected HandoffQueueSize to be capped by 5x pool size (%d), got %d", expectedCap, resultCapped.HandoffQueueSize) |
| 173 | } |
| 174 |
nothing calls this directly
no test coverage detected