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

Function TestConn_UsedMethods

internal/pool/conn_state_test.go:595–637  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

593}
594
595func TestConn_UsedMethods(t *testing.T) {
596 cn := NewConn(nil)
597
598 // Initialize connection to IDLE state
599 cn.stateMachine.Transition(StateInitializing)
600 cn.stateMachine.Transition(StateIdle)
601
602 // Test IsUsed - should be false when IDLE
603 if cn.IsUsed() {
604 t.Error("expected IsUsed to be false for IDLE connection")
605 }
606
607 // Test CompareAndSwapUsed - acquire connection
608 if !cn.CompareAndSwapUsed(false, true) {
609 t.Error("failed to acquire connection with CompareAndSwapUsed")
610 }
611
612 // Test IsUsed - should be true when IN_USE
613 if !cn.IsUsed() {
614 t.Error("expected IsUsed to be true for IN_USE connection")
615 }
616
617 // Test CompareAndSwapUsed - release connection
618 if !cn.CompareAndSwapUsed(true, false) {
619 t.Error("failed to release connection with CompareAndSwapUsed")
620 }
621
622 // Test IsUsed - should be false again
623 if cn.IsUsed() {
624 t.Error("expected IsUsed to be false after release")
625 }
626
627 // Test SetUsed
628 cn.SetUsed(true)
629 if !cn.IsUsed() {
630 t.Error("expected IsUsed to be true after SetUsed(true)")
631 }
632
633 cn.SetUsed(false)
634 if cn.IsUsed() {
635 t.Error("expected IsUsed to be false after SetUsed(false)")
636 }
637}
638
639func TestConnStateMachine_UnusableState(t *testing.T) {
640 sm := NewConnStateMachine()

Callers

nothing calls this directly

Calls 6

IsUsedMethod · 0.95
CompareAndSwapUsedMethod · 0.95
SetUsedMethod · 0.95
NewConnFunction · 0.85
TransitionMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected