(t *testing.T)
| 190 | } |
| 191 | |
| 192 | func 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 | |
| 232 | func TestConnStateMachine_StateString(t *testing.T) { |
| 233 | tests := []struct { |
nothing calls this directly
no test coverage detected