| 457 | } |
| 458 | |
| 459 | func TestAsyncTransitionSpecificState(t *testing.T) { |
| 460 | fsm := NewFSM( |
| 461 | "start", |
| 462 | Events{ |
| 463 | {Name: "run", Src: []string{"start"}, Dst: "end"}, |
| 464 | }, |
| 465 | Callbacks{ |
| 466 | "leave_start": func(_ context.Context, e *Event) { |
| 467 | e.Async() |
| 468 | }, |
| 469 | }, |
| 470 | ) |
| 471 | _ = fsm.Event(context.Background(), "run") |
| 472 | if fsm.Current() != "start" { |
| 473 | t.Error("expected state to be 'start'") |
| 474 | } |
| 475 | err := fsm.Transition() |
| 476 | if err != nil { |
| 477 | t.Errorf("transition failed %v", err) |
| 478 | } |
| 479 | if fsm.Current() != "end" { |
| 480 | t.Error("expected state to be 'end'") |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | func TestAsyncTransitionInProgress(t *testing.T) { |
| 485 | fsm := NewFSM( |