| 1 | package acp |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/control" |
| 8 | ) |
| 9 | |
| 10 | func TestACPBeginRefusesWhileStateChangeIsInFlight(t *testing.T) { |
| 11 | sess := &acpSession{id: "sess-role-switch", ctrl: control.New(control.Options{})} |
| 12 | sess.stateChangeMu.Lock() |
| 13 | if _, _, ok := sess.begin(context.Background()); ok { |
| 14 | sess.stateChangeMu.Unlock() |
| 15 | t.Fatal("begin succeeded while an in-place role switch owned stateChangeMu") |
| 16 | } |
| 17 | sess.stateChangeMu.Unlock() |
| 18 | |
| 19 | _, cancel, ok := sess.begin(context.Background()) |
| 20 | if !ok { |
| 21 | t.Fatal("begin failed after the role switch released stateChangeMu") |
| 22 | } |
| 23 | cancel() |
| 24 | sess.finish() |
| 25 | } |
| 26 |