Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combine: run tests in parallel #95

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 40 additions & 24 deletions actor/combine_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actor_test

import (
"fmt"
"sync/atomic"
"testing"

Expand All @@ -9,21 +10,33 @@ import (
. "github.com/vladopajic/go-actor/actor"
)

func combineParallel(
t *testing.T,
actorsCount int,
testFn func(*testing.T, int),
) {
t.Helper()

t.Run(fmt.Sprintf("actors count %v", actorsCount), func(t *testing.T) {
t.Parallel()
testFn(t, actorsCount)
})
}

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

TestSuite(t, func() Actor {
actors := createActors(0)
return Combine(actors...).Build()
})
combineParallel(t, 0, testCombineTestSuite)
combineParallel(t, 1, testCombineTestSuite)
combineParallel(t, 2, testCombineTestSuite)
combineParallel(t, 10, testCombineTestSuite)
}

TestSuite(t, func() Actor {
actors := createActors(1)
return Combine(actors...).Build()
})
func testCombineTestSuite(t *testing.T, actorsCount int) {
t.Helper()

TestSuite(t, func() Actor {
actors := createActors(10)
actors := createActors(actorsCount)
return Combine(actors...).Build()
})
}
Expand All @@ -32,9 +45,10 @@ func Test_Combine_TestSuite(t *testing.T) {
func Test_Combine(t *testing.T) {
t.Parallel()

testCombine(t, 0)
testCombine(t, 1)
testCombine(t, 5)
combineParallel(t, 0, testCombine)
combineParallel(t, 1, testCombine)
combineParallel(t, 2, testCombine)
combineParallel(t, 10, testCombine)
}

func testCombine(t *testing.T, actorsCount int) {
Expand Down Expand Up @@ -62,9 +76,10 @@ func testCombine(t *testing.T, actorsCount int) {
func Test_Combine_OptOnStopOptOnStart(t *testing.T) {
t.Parallel()

testCombineOptOnStopOptOnStart(t, 0)
testCombineOptOnStopOptOnStart(t, 1)
testCombineOptOnStopOptOnStart(t, 5)
combineParallel(t, 0, testCombineOptOnStopOptOnStart)
combineParallel(t, 1, testCombineOptOnStopOptOnStart)
combineParallel(t, 2, testCombineOptOnStopOptOnStart)
combineParallel(t, 10, testCombineOptOnStopOptOnStart)
}

func testCombineOptOnStopOptOnStart(t *testing.T, actorsCount int) {
Expand Down Expand Up @@ -93,13 +108,14 @@ func testCombineOptOnStopOptOnStart(t *testing.T, actorsCount int) {
func Test_Combine_StoppingOnce(t *testing.T) {
t.Parallel()

testCombineStoppingOnce(t, 1)
testCombineStoppingOnce(t, 2)
testCombineStoppingOnce(t, 10)
testCombineStoppingOnce(t, 20)
combineParallel(t, 0, testCombineStoppingOnce)
combineParallel(t, 1, testCombineStoppingOnce)
combineParallel(t, 2, testCombineStoppingOnce)
combineParallel(t, 10, testCombineStoppingOnce)
combineParallel(t, 20, testCombineStoppingOnce)
}

func testCombineStoppingOnce(t *testing.T, actorsCount int32) {
func testCombineStoppingOnce(t *testing.T, actorsCount int) {
t.Helper()

c := atomic.Int32{}
Expand Down Expand Up @@ -130,7 +146,7 @@ func testCombineStoppingOnce(t *testing.T, actorsCount int32) {
close(stopConcurrentlyFinishedC)
drainC(stopFinsihedC, stopCallsCount)

assert.Equal(t, actorsCount, c.Load())
assert.Equal(t, actorsCount, int(c.Load()))
}

// Test_Combine_OptStopTogether asserts that all actors will end as soon
Expand All @@ -141,9 +157,9 @@ func Test_Combine_OptStopTogether(t *testing.T) {
// no need to test OptStopTogether for actors count < 2
// because single actor is always "stopped together"

testCombineOptStopTogether(t, 1)
testCombineOptStopTogether(t, 2)
testCombineOptStopTogether(t, 10)
combineParallel(t, 1, testCombineOptStopTogether)
combineParallel(t, 2, testCombineOptStopTogether)
combineParallel(t, 10, testCombineOptStopTogether)
}

func testCombineOptStopTogether(t *testing.T, actorsCount int) {
Expand Down
Loading