(t *testing.T)
| 685 | } |
| 686 | |
| 687 | func TestConn_UsableUnusable(t *testing.T) { |
| 688 | cn := NewConn(nil) |
| 689 | |
| 690 | // Initialize connection to IDLE state |
| 691 | cn.stateMachine.Transition(StateInitializing) |
| 692 | cn.stateMachine.Transition(StateIdle) |
| 693 | |
| 694 | // Test IsUsable - should be true when IDLE |
| 695 | if !cn.IsUsable() { |
| 696 | t.Error("expected IsUsable to be true for IDLE connection") |
| 697 | } |
| 698 | |
| 699 | // Test CompareAndSwapUsable - make unusable for background operation |
| 700 | if !cn.CompareAndSwapUsable(true, false) { |
| 701 | t.Error("failed to make connection unusable with CompareAndSwapUsable") |
| 702 | } |
| 703 | |
| 704 | // Verify state is UNUSABLE |
| 705 | if state := cn.stateMachine.GetState(); state != StateUnusable { |
| 706 | t.Errorf("expected state UNUSABLE, got %s", state) |
| 707 | } |
| 708 | |
| 709 | // Test IsUsable - should be false when UNUSABLE |
| 710 | if cn.IsUsable() { |
| 711 | t.Error("expected IsUsable to be false for UNUSABLE connection") |
| 712 | } |
| 713 | |
| 714 | // Test CompareAndSwapUsable - make usable again |
| 715 | if !cn.CompareAndSwapUsable(false, true) { |
| 716 | t.Error("failed to make connection usable with CompareAndSwapUsable") |
| 717 | } |
| 718 | |
| 719 | // Verify state is IDLE |
| 720 | if state := cn.stateMachine.GetState(); state != StateIdle { |
| 721 | t.Errorf("expected state IDLE, got %s", state) |
| 722 | } |
| 723 | |
| 724 | // Test SetUsable(false) |
| 725 | cn.SetUsable(false) |
| 726 | if state := cn.stateMachine.GetState(); state != StateUnusable { |
| 727 | t.Errorf("expected state UNUSABLE after SetUsable(false), got %s", state) |
| 728 | } |
| 729 | |
| 730 | // Test SetUsable(true) |
| 731 | cn.SetUsable(true) |
| 732 | if state := cn.stateMachine.GetState(); state != StateIdle { |
| 733 | t.Errorf("expected state IDLE after SetUsable(true), got %s", state) |
| 734 | } |
| 735 | } |
nothing calls this directly
no test coverage detected