From cb40f966839362d26a78c56651a88b546c0dec20 Mon Sep 17 00:00:00 2001 From: Andrei Tonkikh Date: Thu, 23 Jun 2022 21:48:53 +0200 Subject: [PATCH] Add tests for negative cases --- pkg/dsl/dslmodule_test.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/dsl/dslmodule_test.go b/pkg/dsl/dslmodule_test.go index c49ba5da2..129f6d68f 100644 --- a/pkg/dsl/dslmodule_test.go +++ b/pkg/dsl/dslmodule_test.go @@ -6,6 +6,7 @@ import ( "github.com/filecoin-project/mir/pkg/events" "github.com/filecoin-project/mir/pkg/modules" "github.com/filecoin-project/mir/pkg/pb/eventpb" + "github.com/filecoin-project/mir/pkg/pb/messagepb" "github.com/filecoin-project/mir/pkg/types" "github.com/filecoin-project/mir/pkg/util/mathutil" "github.com/filecoin-project/mir/pkg/util/sliceutil" @@ -97,6 +98,13 @@ func newSimpleTestingModule(mc *simpleModuleConfig) modules.PassiveModule { return nil }) + UponCondition(m, func() error { + if uintsSum > 100_000 { + return errors.New("too much!") + } + return nil + }) + return m } @@ -145,6 +153,16 @@ func TestDslModule_ApplyEvents(t *testing.T) { events.TestingUint(mc.Reports, 300), events.TestingUint(mc.Reports, 400), events.TestingUint(mc.Reports, 500)), }, + "test unknown event type": { + eventsIn: events.ListOf(events.SendMessage(mc.Self, &messagepb.Message{}, []types.NodeID{})), + eventsOut: events.EmptyList(), + err: errors.New("unknown event type '*eventpb.Event_SendMessage'"), + }, + "test failed condition": { + eventsIn: events.ListOf(events.TestingUint(mc.Self, 999_999_999)), + eventsOut: events.EmptyList(), + err: errors.New("too much!"), + }, } for testName, tc := range tests { @@ -270,7 +288,7 @@ func TestDslModule_ContextRecoveryAndCleanup(t *testing.T) { testCases := map[string]func(mc *contextTestingModuleModuleConfig, m Module){ "empty": func(mc *contextTestingModuleModuleConfig, m Module) {}, - "request_response": func(mc *contextTestingModuleModuleConfig, m Module) { + "request response": func(mc *contextTestingModuleModuleConfig, m Module) { eventsOut, err := m.ApplyEvents(events.ListOf(events.TestingString(mc.Self, "hello"))) assert.Nil(t, err) assert.Equal(t, 2, eventsOut.Len()) @@ -288,7 +306,7 @@ func TestDslModule_ContextRecoveryAndCleanup(t *testing.T) { assert.Equal(t, []*eventpb.Event{events.TestingString(mc.Hashed, "hello: world")}, eventsOut.Slice()) }, - "response_without_request": func(mc *contextTestingModuleModuleConfig, m Module) { + "response without request": func(mc *contextTestingModuleModuleConfig, m Module) { assert.Panics(t, func() { // Context with id 42 doesn't exist. The module should panic. _, _ = m.ApplyEvents(events.ListOf( @@ -296,7 +314,7 @@ func TestDslModule_ContextRecoveryAndCleanup(t *testing.T) { }) }, - "check_context_is_disposed": func(mc *contextTestingModuleModuleConfig, m Module) { + "check context is disposed": func(mc *contextTestingModuleModuleConfig, m Module) { eventsOut, err := m.ApplyEvents(events.ListOf(events.TestingString(mc.Self, "hello"))) assert.Nil(t, err) assert.Equal(t, 2, eventsOut.Len()) @@ -316,7 +334,7 @@ func TestDslModule_ContextRecoveryAndCleanup(t *testing.T) { }) }, - "check_multiple_handlers_for_response": func(mc *contextTestingModuleModuleConfig, m Module) { + "check multiple handlers for response": func(mc *contextTestingModuleModuleConfig, m Module) { eventsOut, err := m.ApplyEvents(events.ListOf(events.TestingUint(mc.Self, 8))) assert.Nil(t, err) assert.Equal(t, 1, eventsOut.Len())