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

Function TestConnStateMachine_ConcurrentAccess

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

Source from the content-addressed store, hash-verified

190}
191
192func TestConnStateMachine_ConcurrentAccess(t *testing.T) {
193 sm := NewConnStateMachine()
194 sm.Transition(StateIdle)
195
196 const numGoroutines = 100
197 const numIterations = 100
198
199 var wg sync.WaitGroup
200 var successCount atomic.Int32
201
202 for i := 0; i < numGoroutines; i++ {
203 wg.Add(1)
204 go func() {
205 defer wg.Done()
206
207 for j := 0; j < numIterations; j++ {
208 // Try to transition from READY to REAUTH_IN_PROGRESS
209 _, err := sm.TryTransition([]ConnState{StateIdle}, StateUnusable)
210 if err == nil {
211 successCount.Add(1)
212 // Transition back to READY
213 sm.Transition(StateIdle)
214 }
215
216 // Read state (hot path)
217 _ = sm.GetState()
218 }
219 }()
220 }
221
222 wg.Wait()
223
224 // At least some transitions should have succeeded
225 if successCount.Load() == 0 {
226 t.Error("expected at least some successful transitions")
227 }
228
229 t.Logf("Successful transitions: %d out of %d attempts", successCount.Load(), numGoroutines*numIterations)
230}
231
232func TestConnStateMachine_StateString(t *testing.T) {
233 tests := []struct {

Callers

nothing calls this directly

Calls 8

TransitionMethod · 0.95
TryTransitionMethod · 0.95
GetStateMethod · 0.95
NewConnStateMachineFunction · 0.85
WaitMethod · 0.80
AddMethod · 0.65
LoadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected