TestDialerRetryConfiguration tests the new DialerRetries and DialerRetryTimeout options
(t *testing.T)
| 468 | |
| 469 | // TestDialerRetryConfiguration tests the new DialerRetries and DialerRetryTimeout options |
| 470 | func TestDialerRetryConfiguration(t *testing.T) { |
| 471 | ctx := context.Background() |
| 472 | |
| 473 | t.Run("CustomDialerRetries", func(t *testing.T) { |
| 474 | var attempts int64 |
| 475 | failingDialer := func(ctx context.Context) (net.Conn, error) { |
| 476 | atomic.AddInt64(&attempts, 1) |
| 477 | return nil, errors.New("dial failed") |
| 478 | } |
| 479 | |
| 480 | connPool := pool.NewConnPool(&pool.Options{ |
| 481 | Dialer: failingDialer, |
| 482 | PoolSize: 1, |
| 483 | MaxConcurrentDials: 1, |
| 484 | PoolTimeout: time.Second, |
| 485 | DialTimeout: time.Second, |
| 486 | DialerRetries: 3, // Custom retry count |
| 487 | DialerRetryTimeout: 10 * time.Millisecond, // Fast retries for testing |
| 488 | }) |
| 489 | defer connPool.Close() |
| 490 | |
| 491 | _, err := connPool.Get(ctx) |
| 492 | if err == nil { |
| 493 | t.Error("Expected error from failing dialer") |
| 494 | } |
| 495 | |
| 496 | // Should have attempted at least 3 times (DialerRetries = 3) |
| 497 | // There might be additional attempts due to pool logic |
| 498 | finalAttempts := atomic.LoadInt64(&attempts) |
| 499 | if finalAttempts < 3 { |
| 500 | t.Errorf("Expected at least 3 dial attempts, got %d", finalAttempts) |
| 501 | } |
| 502 | if finalAttempts > 6 { |
| 503 | t.Errorf("Expected around 3 dial attempts, got %d (too many)", finalAttempts) |
| 504 | } |
| 505 | }) |
| 506 | |
| 507 | t.Run("DefaultDialerRetries", func(t *testing.T) { |
| 508 | var attempts int64 |
| 509 | failingDialer := func(ctx context.Context) (net.Conn, error) { |
| 510 | atomic.AddInt64(&attempts, 1) |
| 511 | return nil, errors.New("dial failed") |
| 512 | } |
| 513 | |
| 514 | connPool := pool.NewConnPool(&pool.Options{ |
| 515 | Dialer: failingDialer, |
| 516 | PoolSize: 1, |
| 517 | MaxConcurrentDials: 1, |
| 518 | PoolTimeout: time.Second, |
| 519 | DialTimeout: time.Second, |
| 520 | // DialerRetries and DialerRetryTimeout not set - should use defaults |
| 521 | }) |
| 522 | defer connPool.Close() |
| 523 | |
| 524 | _, err := connPool.Get(ctx) |
| 525 | if err == nil { |
| 526 | t.Error("Expected error from failing dialer") |
| 527 | } |
nothing calls this directly
no test coverage detected