MCPcopy
hub / github.com/looplab/fsm / TestAsyncTransitionInProgress

Function TestAsyncTransitionInProgress

fsm_test.go:484–513  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

482}
483
484func TestAsyncTransitionInProgress(t *testing.T) {
485 fsm := NewFSM(
486 "start",
487 Events{
488 {Name: "run", Src: []string{"start"}, Dst: "end"},
489 {Name: "reset", Src: []string{"end"}, Dst: "start"},
490 },
491 Callbacks{
492 "leave_start": func(_ context.Context, e *Event) {
493 e.Async()
494 },
495 },
496 )
497 _ = fsm.Event(context.Background(), "run")
498 err := fsm.Event(context.Background(), "reset")
499 if e, ok := err.(InTransitionError); !ok && e.Event != "reset" {
500 t.Error("expected 'InTransitionError' with correct state")
501 }
502 err = fsm.Transition()
503 if err != nil {
504 t.Errorf("transition failed %v", err)
505 }
506 err = fsm.Event(context.Background(), "reset")
507 if err != nil {
508 t.Errorf("transition failed %v", err)
509 }
510 if fsm.Current() != "start" {
511 t.Error("expected state to be 'start'")
512 }
513}
514
515func TestAsyncTransitionNotInProgress(t *testing.T) {
516 fsm := NewFSM(

Callers

nothing calls this directly

Calls 6

EventMethod · 0.95
TransitionMethod · 0.95
CurrentMethod · 0.95
NewFSMFunction · 0.85
AsyncMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…