Skip to content

Commit

Permalink
fix: Enable parallel testing where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
maxekman committed Oct 22, 2021
1 parent 139df9a commit 7917d26
Show file tree
Hide file tree
Showing 35 changed files with 173 additions and 6 deletions.
8 changes: 8 additions & 0 deletions aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
)

func TestCreateAggregate(t *testing.T) {
t.Parallel()

id := uuid.New()
_, err := CreateAggregate(TestAggregateRegisterType, id)
if !errors.Is(err, ErrAggregateNotRegistered) {
Expand All @@ -47,6 +49,8 @@ func TestCreateAggregate(t *testing.T) {
}

func TestRegisterAggregateEmptyName(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: attempt to register empty aggregate type" {
t.Error("there should have been a panic:", r)
Expand All @@ -58,6 +62,8 @@ func TestRegisterAggregateEmptyName(t *testing.T) {
}

func TestRegisterAggregateNil(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: created aggregate is nil" {
t.Error("there should have been a panic:", r)
Expand All @@ -67,6 +73,8 @@ func TestRegisterAggregateNil(t *testing.T) {
}

func TestRegisterAggregateTwice(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: registering duplicate types for \"TestAggregateRegisterTwice\"" {
t.Error("there should have been a panic:", r)
Expand Down
6 changes: 6 additions & 0 deletions aggregatestore/events/aggregatebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
)

func TestNewAggregateBase(t *testing.T) {
t.Parallel()

id := uuid.New()
agg := NewAggregateBase(TestAggregateType, id)
if agg == nil {
Expand All @@ -42,6 +44,8 @@ func TestNewAggregateBase(t *testing.T) {
}

func TestAggregateVersion(t *testing.T) {
t.Parallel()

agg := NewAggregateBase(TestAggregateType, uuid.New())
if agg.AggregateVersion() != 0 {
t.Error("the version should be 0:", agg.AggregateVersion())
Expand All @@ -54,6 +58,8 @@ func TestAggregateVersion(t *testing.T) {
}

func TestAggregateEvents(t *testing.T) {
t.Parallel()

id := uuid.New()
agg := NewTestAggregate(id)
timestamp := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
Expand Down
12 changes: 12 additions & 0 deletions aggregatestore/events/aggregatestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
)

func TestNewAggregateStore(t *testing.T) {
t.Parallel()

eventStore := &mocks.EventStore{
Events: make([]eh.Event, 0),
}
Expand All @@ -49,6 +51,8 @@ func TestNewAggregateStore(t *testing.T) {
}

func TestAggregateStore_LoadNoEvents(t *testing.T) {
t.Parallel()

store, _ := createStore(t)

ctx := context.Background()
Expand All @@ -71,6 +75,8 @@ func TestAggregateStore_LoadNoEvents(t *testing.T) {
}

func TestAggregateStore_LoadEvents(t *testing.T) {
t.Parallel()

store, eventStore := createStore(t)

ctx := context.Background()
Expand Down Expand Up @@ -133,6 +139,8 @@ func TestAggregateStore_LoadEvents(t *testing.T) {
}

func TestAggregateStore_LoadEvents_MismatchedEventType(t *testing.T) {
t.Parallel()

store, eventStore := createStore(t)

ctx := context.Background()
Expand Down Expand Up @@ -162,6 +170,8 @@ func TestAggregateStore_LoadEvents_MismatchedEventType(t *testing.T) {
}

func TestAggregateStore_SaveEvents(t *testing.T) {
t.Parallel()

store, eventStore := createStore(t)

ctx := context.Background()
Expand Down Expand Up @@ -222,6 +232,8 @@ func TestAggregateStore_SaveEvents(t *testing.T) {
}

func TestAggregateStore_AggregateNotRegistered(t *testing.T) {
t.Parallel()

store, _ := createStore(t)

ctx := context.Background()
Expand Down
12 changes: 12 additions & 0 deletions aggregatestore/model/aggregatestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
)

func TestNewAggregateStore(t *testing.T) {
t.Parallel()

repo := &mocks.Repo{}
bus := &mocks.EventBus{
Events: make([]eh.Event, 0),
Expand All @@ -50,6 +52,8 @@ func TestNewAggregateStore(t *testing.T) {
}

func TestAggregateStore_LoadNotFound(t *testing.T) {
t.Parallel()

store, repo, _ := createStore(t)

ctx := context.Background()
Expand All @@ -66,6 +70,8 @@ func TestAggregateStore_LoadNotFound(t *testing.T) {
}

func TestAggregateStore_Load(t *testing.T) {
t.Parallel()

store, repo, _ := createStore(t)

ctx := context.Background()
Expand All @@ -92,6 +98,8 @@ func TestAggregateStore_Load(t *testing.T) {
}

func TestAggregateStore_Load_InvalidAggregate(t *testing.T) {
t.Parallel()

store, repo, _ := createStore(t)

ctx := context.Background()
Expand All @@ -114,6 +122,8 @@ func TestAggregateStore_Load_InvalidAggregate(t *testing.T) {
}

func TestAggregateStore_Save(t *testing.T) {
t.Parallel()

store, repo, _ := createStore(t)

ctx := context.Background()
Expand All @@ -139,6 +149,8 @@ func TestAggregateStore_Save(t *testing.T) {
}

func TestAggregateStore_SaveWithPublish(t *testing.T) {
t.Parallel()

store, repo, bus := createStore(t)

ctx := context.Background()
Expand Down
2 changes: 2 additions & 0 deletions codec/bson/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

func TestEventCodec(t *testing.T) {
t.Parallel()

c := &EventCodec{}
expectedBytes, err := base64.StdEncoding.DecodeString("4QEAAAJldmVudF90eXBlAAsAAABDb2RlY0V2ZW50AANkYXRhAAwBAAAIYm9vbAABAnN0cmluZwAHAAAAc3RyaW5nAAFudW1iZXIAAAAAAAAARUAEc2xpY2UAFwAAAAIwAAIAAABhAAIxAAIAAABiAAADbWFwABQAAAACa2V5AAYAAAB2YWx1ZQAACXRpbWUAgDVT4CQBAAAJdGltZXJlZgCANVPgJAEAAApudWxsdGltZQADc3RydWN0AC8AAAAIYm9vbAABAnN0cmluZwAHAAAAc3RyaW5nAAFudW1iZXIAAAAAAAAARUAAA3N0cnVjdHJlZgAvAAAACGJvb2wAAQJzdHJpbmcABwAAAHN0cmluZwABbnVtYmVyAAAAAAAAAEVAAApudWxsc3RydWN0AAAJdGltZXN0YW1wAIA1U+AkAQAAAmFnZ3JlZ2F0ZV90eXBlAAoAAABBZ2dyZWdhdGUAAl9pZAAlAAAAMTBhN2VjMGYtN2YyYi00NmY1LWJjYTEtODc3YjZlMzNjOWZkABB2ZXJzaW9uAAEAAAADbWV0YWRhdGEAEgAAAAFudW0AAAAAAAAARUAAA2NvbnRleHQAHgAAAAJjb250ZXh0X29uZQAIAAAAdGVzdHZhbAAAAA==")
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions codec/json/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

func TestEventCodec(t *testing.T) {
t.Parallel()

c := &EventCodec{}
expectedBytes := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(`
{
Expand Down
12 changes: 12 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

func TestCreateCommand(t *testing.T) {
t.Parallel()

_, err := CreateCommand(TestCommandRegisterType)
if !errors.Is(err, ErrCommandNotRegistered) {
t.Error("there should be a command not registered error:", err)
Expand All @@ -39,6 +41,8 @@ func TestCreateCommand(t *testing.T) {
}

func TestRegisterCommandEmptyName(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: attempt to register empty command type" {
t.Error("there should have been a panic:", r)
Expand All @@ -48,6 +52,8 @@ func TestRegisterCommandEmptyName(t *testing.T) {
}

func TestRegisterCommandNil(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: created command is nil" {
t.Error("there should have been a panic:", r)
Expand All @@ -57,6 +63,8 @@ func TestRegisterCommandNil(t *testing.T) {
}

func TestRegisterCommandTwice(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: registering duplicate types for \"TestCommandRegisterTwice\"" {
t.Error("there should have been a panic:", r)
Expand All @@ -67,6 +75,8 @@ func TestRegisterCommandTwice(t *testing.T) {
}

func TestUnregisterCommandEmptyName(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: attempt to unregister empty command type" {
t.Error("there should have been a panic:", r)
Expand All @@ -76,6 +86,8 @@ func TestUnregisterCommandEmptyName(t *testing.T) {
}

func TestUnregisterCommandTwice(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: unregister of non-registered type \"TestCommandUnregisterTwice\"" {
t.Error("there should have been a panic:", r)
Expand Down
12 changes: 12 additions & 0 deletions commandhandler/aggregate/commandhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

func TestNewCommandHandler(t *testing.T) {
t.Parallel()

store := &mocks.AggregateStore{
Aggregates: make(map[uuid.UUID]eh.Aggregate),
}
Expand All @@ -47,6 +49,8 @@ func TestNewCommandHandler(t *testing.T) {
}

func TestCommandHandler(t *testing.T) {
t.Parallel()

a, h, _ := createAggregateAndHandler(t)

ctx := context.WithValue(context.Background(), "testkey", "testval")
Expand All @@ -68,6 +72,8 @@ func TestCommandHandler(t *testing.T) {
}

func TestCommandHandler_AggregateNotFound(t *testing.T) {
t.Parallel()

store := &mocks.AggregateStore{
Aggregates: map[uuid.UUID]eh.Aggregate{},
}
Expand All @@ -90,6 +96,8 @@ func TestCommandHandler_AggregateNotFound(t *testing.T) {
}

func TestCommandHandler_ErrorInHandler(t *testing.T) {
t.Parallel()

a, h, _ := createAggregateAndHandler(t)

commandErr := errors.New("command error")
Expand All @@ -109,6 +117,8 @@ func TestCommandHandler_ErrorInHandler(t *testing.T) {
}

func TestCommandHandler_ErrorWhenSaving(t *testing.T) {
t.Parallel()

a, h, store := createAggregateAndHandler(t)

saveErr := errors.New("save error")
Expand All @@ -124,6 +134,8 @@ func TestCommandHandler_ErrorWhenSaving(t *testing.T) {
}

func TestCommandHandler_NoHandlers(t *testing.T) {
t.Parallel()

_, h, _ := createAggregateAndHandler(t)

cmd := &mocks.Command{
Expand Down
2 changes: 2 additions & 0 deletions commandhandler/bus/commandhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

func TestCommandHandler(t *testing.T) {
t.Parallel()

bus := NewCommandHandler()
if bus == nil {
t.Fatal("there should be a bus")
Expand Down
4 changes: 4 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
)

func TestContextMarshaler(t *testing.T) {
t.Parallel()

if len(contextMarshalFuncs) != 1 {
t.Error("there should be one context marshaler")
}
Expand All @@ -46,6 +48,8 @@ func TestContextMarshaler(t *testing.T) {
}

func TestContextUnmarshaler(t *testing.T) {
t.Parallel()

if len(contextUnmarshalFuncs) != 1 {
t.Error("there should be one context marshaler")
}
Expand Down
12 changes: 12 additions & 0 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
)

func TestNewEvent(t *testing.T) {
t.Parallel()

timestamp := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
event := NewEvent(TestEventType, &TestEventData{"event1"}, timestamp)
if event.EventType() != TestEventType {
Expand Down Expand Up @@ -85,6 +87,8 @@ func TestNewEvent(t *testing.T) {
}

func TestCreateEventData(t *testing.T) {
t.Parallel()

data, err := CreateEventData(TestEventRegisterType)
if !errors.Is(err, ErrEventDataNotRegistered) {
t.Error("there should be a event not registered error:", err)
Expand All @@ -109,6 +113,8 @@ func TestCreateEventData(t *testing.T) {
}

func TestRegisterEventEmptyName(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: attempt to register empty event type" {
t.Error("there should have been a panic:", r)
Expand All @@ -120,6 +126,8 @@ func TestRegisterEventEmptyName(t *testing.T) {
}

func TestRegisterEventTwice(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: registering duplicate types for \"TestEventRegisterTwice\"" {
t.Error("there should have been a panic:", r)
Expand All @@ -134,6 +142,8 @@ func TestRegisterEventTwice(t *testing.T) {
}

func TestUnregisterEventEmptyName(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: attempt to unregister empty event type" {
t.Error("there should have been a panic:", r)
Expand All @@ -143,6 +153,8 @@ func TestUnregisterEventEmptyName(t *testing.T) {
}

func TestUnregisterEventTwice(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil || r != "eventhorizon: unregister of non-registered type \"TestEventUnregisterTwice\"" {
t.Error("there should have been a panic:", r)
Expand Down
6 changes: 3 additions & 3 deletions eventbus/local/eventbus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import (

// NOTE: Not named "Integration" to enable running with the unit tests.
func TestAddHandler(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
t.Parallel()

bus := NewEventBus()
if bus == nil {
Expand All @@ -37,6 +35,8 @@ func TestAddHandler(t *testing.T) {

// NOTE: Not named "Integration" to enable running with the unit tests.
func TestEventBus(t *testing.T) {
t.Parallel()

group := NewGroup()
if group == nil {
t.Fatal("there should be a group")
Expand Down
Loading

0 comments on commit 7917d26

Please sign in to comment.