Skip to content

Commit 6355bd2

Browse files
authored
combine: run tests in parallel (#95)
1 parent 1c17c7c commit 6355bd2

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

actor/combine_test.go

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package actor_test
22

33
import (
4+
"fmt"
45
"sync/atomic"
56
"testing"
67

@@ -9,21 +10,33 @@ import (
910
. "github.com/vladopajic/go-actor/actor"
1011
)
1112

13+
func combineParallel(
14+
t *testing.T,
15+
actorsCount int,
16+
testFn func(*testing.T, int),
17+
) {
18+
t.Helper()
19+
20+
t.Run(fmt.Sprintf("actors count %v", actorsCount), func(t *testing.T) {
21+
t.Parallel()
22+
testFn(t, actorsCount)
23+
})
24+
}
25+
1226
func Test_Combine_TestSuite(t *testing.T) {
1327
t.Parallel()
1428

15-
TestSuite(t, func() Actor {
16-
actors := createActors(0)
17-
return Combine(actors...).Build()
18-
})
29+
combineParallel(t, 0, testCombineTestSuite)
30+
combineParallel(t, 1, testCombineTestSuite)
31+
combineParallel(t, 2, testCombineTestSuite)
32+
combineParallel(t, 10, testCombineTestSuite)
33+
}
1934

20-
TestSuite(t, func() Actor {
21-
actors := createActors(1)
22-
return Combine(actors...).Build()
23-
})
35+
func testCombineTestSuite(t *testing.T, actorsCount int) {
36+
t.Helper()
2437

2538
TestSuite(t, func() Actor {
26-
actors := createActors(10)
39+
actors := createActors(actorsCount)
2740
return Combine(actors...).Build()
2841
})
2942
}
@@ -32,9 +45,10 @@ func Test_Combine_TestSuite(t *testing.T) {
3245
func Test_Combine(t *testing.T) {
3346
t.Parallel()
3447

35-
testCombine(t, 0)
36-
testCombine(t, 1)
37-
testCombine(t, 5)
48+
combineParallel(t, 0, testCombine)
49+
combineParallel(t, 1, testCombine)
50+
combineParallel(t, 2, testCombine)
51+
combineParallel(t, 10, testCombine)
3852
}
3953

4054
func testCombine(t *testing.T, actorsCount int) {
@@ -62,9 +76,10 @@ func testCombine(t *testing.T, actorsCount int) {
6276
func Test_Combine_OptOnStopOptOnStart(t *testing.T) {
6377
t.Parallel()
6478

65-
testCombineOptOnStopOptOnStart(t, 0)
66-
testCombineOptOnStopOptOnStart(t, 1)
67-
testCombineOptOnStopOptOnStart(t, 5)
79+
combineParallel(t, 0, testCombineOptOnStopOptOnStart)
80+
combineParallel(t, 1, testCombineOptOnStopOptOnStart)
81+
combineParallel(t, 2, testCombineOptOnStopOptOnStart)
82+
combineParallel(t, 10, testCombineOptOnStopOptOnStart)
6883
}
6984

7085
func testCombineOptOnStopOptOnStart(t *testing.T, actorsCount int) {
@@ -93,13 +108,14 @@ func testCombineOptOnStopOptOnStart(t *testing.T, actorsCount int) {
93108
func Test_Combine_StoppingOnce(t *testing.T) {
94109
t.Parallel()
95110

96-
testCombineStoppingOnce(t, 1)
97-
testCombineStoppingOnce(t, 2)
98-
testCombineStoppingOnce(t, 10)
99-
testCombineStoppingOnce(t, 20)
111+
combineParallel(t, 0, testCombineStoppingOnce)
112+
combineParallel(t, 1, testCombineStoppingOnce)
113+
combineParallel(t, 2, testCombineStoppingOnce)
114+
combineParallel(t, 10, testCombineStoppingOnce)
115+
combineParallel(t, 20, testCombineStoppingOnce)
100116
}
101117

102-
func testCombineStoppingOnce(t *testing.T, actorsCount int32) {
118+
func testCombineStoppingOnce(t *testing.T, actorsCount int) {
103119
t.Helper()
104120

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

133-
assert.Equal(t, actorsCount, c.Load())
149+
assert.Equal(t, actorsCount, int(c.Load()))
134150
}
135151

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

144-
testCombineOptStopTogether(t, 1)
145-
testCombineOptStopTogether(t, 2)
146-
testCombineOptStopTogether(t, 10)
160+
combineParallel(t, 1, testCombineOptStopTogether)
161+
combineParallel(t, 2, testCombineOptStopTogether)
162+
combineParallel(t, 10, testCombineOptStopTogether)
147163
}
148164

149165
func testCombineOptStopTogether(t *testing.T, actorsCount int) {

0 commit comments

Comments
 (0)