From 88c2d1bc9b7fc6e65633043bfae1424dfea4ef9a Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Thu, 15 Aug 2024 14:12:21 +1000 Subject: [PATCH] add tests for bad transitions with fsmnext --- backend/controller/dal/fsm_integration_test.go | 4 ++++ .../dal/testdata/go/fsmnext/fsmnext_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/backend/controller/dal/fsm_integration_test.go b/backend/controller/dal/fsm_integration_test.go index b829a208d8..6ab7cad222 100644 --- a/backend/controller/dal/fsm_integration_test.go +++ b/backend/controller/dal/fsm_integration_test.go @@ -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"`), ) } diff --git a/backend/controller/dal/testdata/go/fsmnext/fsmnext_test.go b/backend/controller/dal/testdata/go/fsmnext/fsmnext_test.go index f7ed57c069..294e5816e4 100644 --- a/backend/controller/dal/testdata/go/fsmnext/fsmnext_test.go +++ b/backend/controller/dal/testdata/go/fsmnext/fsmnext_test.go @@ -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"`) +}