Skip to content

Commit

Permalink
add tests for bad transitions with fsmnext
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Aug 15, 2024
1 parent 0a6d695 commit 88c2d1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/controller/dal/fsm_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,15 @@ func TestFSMNext(t *testing.T) {
// Schedule next and then error and retry. Each error should be the expected error, not a failure to schedule the next state
transitionFSMWithOptions("3", 1, optional.Some("computers are fun"), "A", "B"),

// Bad progression
transitionFSM("4", "A", "B", "B"),

in.Sleep(4*time.Second),

checkAsyncCall("1", "A", "B", "C", "D"),
checkRepeatedAsyncCallError("2", "A", "fsm instance already has its next state set"),
// will get "fsm instance already has its next state set" if next event is not cleared properly
checkRepeatedAsyncCallError("3", "A", "computers are fun"),
checkRepeatedAsyncCallError("4", "B", `invalid event "fsmnext.EventB" for state "fsmnext.stateB"`),
)
}
13 changes: 13 additions & 0 deletions backend/controller/dal/testdata/go/fsmnext/fsmnext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ func TestDoubleNext(t *testing.T) {
},
}).Error(), `fsm "fsm" instance "1" already has a pending event`)
}

func TestBadProgression(t *testing.T) {
// Simple progression through each state
ctx := ftltest.Context()

assert.EqualError(t, SendOne(ctx, Request{
State: A,
Event: Event{
Instance: "1",
NextStates: []State{B, C, C},
},
}), `invalid event "fsmnext.EventC" for state "fsmnext.EventC"`)
}

0 comments on commit 88c2d1b

Please sign in to comment.