(t *testing.T)
| 637 | } |
| 638 | |
| 639 | func TestConnStateMachine_UnusableState(t *testing.T) { |
| 640 | sm := NewConnStateMachine() |
| 641 | |
| 642 | // Initialize to IDLE state |
| 643 | sm.Transition(StateInitializing) |
| 644 | sm.Transition(StateIdle) |
| 645 | |
| 646 | // Test IDLE → UNUSABLE transition (for background operations) |
| 647 | _, err := sm.TryTransition([]ConnState{StateIdle}, StateUnusable) |
| 648 | if err != nil { |
| 649 | t.Errorf("failed to transition from IDLE to UNUSABLE: %v", err) |
| 650 | } |
| 651 | if state := sm.GetState(); state != StateUnusable { |
| 652 | t.Errorf("expected state UNUSABLE, got %s", state) |
| 653 | } |
| 654 | |
| 655 | // Test UNUSABLE → IDLE transition (after background operation completes) |
| 656 | _, err = sm.TryTransition([]ConnState{StateUnusable}, StateIdle) |
| 657 | if err != nil { |
| 658 | t.Errorf("failed to transition from UNUSABLE to IDLE: %v", err) |
| 659 | } |
| 660 | if state := sm.GetState(); state != StateIdle { |
| 661 | t.Errorf("expected state IDLE, got %s", state) |
| 662 | } |
| 663 | |
| 664 | // Test that we can transition from IN_USE to UNUSABLE if needed |
| 665 | // (e.g., for urgent handoff while connection is in use) |
| 666 | sm.Transition(StateInUse) |
| 667 | _, err = sm.TryTransition([]ConnState{StateInUse}, StateUnusable) |
| 668 | if err != nil { |
| 669 | t.Errorf("failed to transition from IN_USE to UNUSABLE: %v", err) |
| 670 | } |
| 671 | if state := sm.GetState(); state != StateUnusable { |
| 672 | t.Errorf("expected state UNUSABLE, got %s", state) |
| 673 | } |
| 674 | |
| 675 | // Test UNUSABLE → INITIALIZING transition (for handoff) |
| 676 | sm.Transition(StateIdle) |
| 677 | sm.Transition(StateUnusable) |
| 678 | _, err = sm.TryTransition([]ConnState{StateUnusable}, StateInitializing) |
| 679 | if err != nil { |
| 680 | t.Errorf("failed to transition from UNUSABLE to INITIALIZING: %v", err) |
| 681 | } |
| 682 | if state := sm.GetState(); state != StateInitializing { |
| 683 | t.Errorf("expected state INITIALIZING, got %s", state) |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | func TestConn_UsableUnusable(t *testing.T) { |
| 688 | cn := NewConn(nil) |
nothing calls this directly
no test coverage detected