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

Function TestIntegrationWithApplyDefaults

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

Source from the content-addressed store, hash-verified

293}
294
295func TestIntegrationWithApplyDefaults(t *testing.T) {
296 t.Run("ProcessorWithPartialConfigAppliesDefaults", func(t *testing.T) {
297 // Create a partial config with only some fields set
298 partialConfig := &Config{
299 MaxWorkers: 15, // Custom value (>= 10 to test preservation)
300 // Other fields left as zero values - should get defaults
301 }
302
303 baseDialer := func(ctx context.Context, network, addr string) (net.Conn, error) {
304 return &mockNetConn{addr: addr}, nil
305 }
306
307 // Create processor - should apply defaults to missing fields
308 processor := NewPoolHook(baseDialer, "tcp", partialConfig, nil)
309 defer processor.Shutdown(context.Background())
310
311 // Processor should be created successfully
312 if processor == nil {
313 t.Error("Processor should be created with partial config")
314 }
315
316 // Test that the ApplyDefaults method worked correctly by creating the same config
317 // and applying defaults manually
318 expectedConfig := partialConfig.ApplyDefaultsWithPoolSize(100) // Use explicit pool size for testing
319
320 // Should preserve custom values (when >= poolSize/2)
321 if expectedConfig.MaxWorkers != 50 { // max(poolSize/2, 15) = max(50, 15) = 50
322 t.Errorf("Expected MaxWorkers to be 50, got %d", expectedConfig.MaxWorkers)
323 }
324
325 // Should apply defaults for missing fields (auto-calculated queue size with hybrid scaling)
326 workerBasedSize := expectedConfig.MaxWorkers * 20
327 poolSize := 100 // Default pool size used in ApplyDefaults
328 poolBasedSize := poolSize
329 expectedQueueSize := max(workerBasedSize, poolBasedSize)
330 expectedQueueSize = min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
331 if expectedConfig.HandoffQueueSize != expectedQueueSize {
332 t.Errorf("Expected HandoffQueueSize to be %d (max(20*MaxWorkers=%d, poolSize=%d) capped by 5*poolSize=%d), got %d",
333 expectedQueueSize, workerBasedSize, poolBasedSize, poolSize*5, expectedConfig.HandoffQueueSize)
334 }
335
336 // Test that queue size is always capped by 5x pool size
337 if expectedConfig.HandoffQueueSize > poolSize*5 {
338 t.Errorf("HandoffQueueSize (%d) should never exceed 5x pool size (%d)",
339 expectedConfig.HandoffQueueSize, poolSize*2)
340 }
341
342 if expectedConfig.RelaxedTimeout != 10*time.Second {
343 t.Errorf("Expected RelaxedTimeout to be 10s (default), got %v", expectedConfig.RelaxedTimeout)
344 }
345
346 if expectedConfig.HandoffTimeout != 15*time.Second {
347 t.Errorf("Expected HandoffTimeout to be 15s (default), got %v", expectedConfig.HandoffTimeout)
348 }
349
350 if expectedConfig.PostHandoffRelaxedDuration != 20*time.Second {
351 t.Errorf("Expected PostHandoffRelaxedDuration to be 20s (2x RelaxedTimeout), got %v", expectedConfig.PostHandoffRelaxedDuration)
352 }

Callers

nothing calls this directly

Calls 5

ShutdownMethod · 0.95
NewPoolHookFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected