Skip to content

Commit af7094e

Browse files
committed
combine: add Test_Combine_OthersNotStopped
1 parent 6355bd2 commit af7094e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

actor/combine_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"sync/atomic"
66
"testing"
7+
"time"
78

89
"github.com/stretchr/testify/assert"
910

@@ -183,6 +184,52 @@ func testCombineOptStopTogether(t *testing.T, actorsCount int) {
183184
}
184185
}
185186

187+
// Test_Combine_OthersNotStopped asserts that if any of underlaying
188+
// actors end it wont affect other actors. This is default behavior when
189+
// `OptStopTogether` is not provided.
190+
func Test_Combine_OthersNotStopped(t *testing.T) {
191+
t.Parallel()
192+
193+
combineParallel(t, 1, testCombineOthersNotStopped)
194+
combineParallel(t, 2, testCombineOthersNotStopped)
195+
combineParallel(t, 10, testCombineOthersNotStopped)
196+
}
197+
198+
func testCombineOthersNotStopped(t *testing.T, actorsCount int) {
199+
t.Helper()
200+
201+
for i := range actorsCount {
202+
onStartC := make(chan any, actorsCount)
203+
onStopC := make(chan any, actorsCount)
204+
onStart := OptOnStart(func(Context) { onStartC <- `🌞` })
205+
onStop := OptOnStop(func() { onStopC <- `🌚` })
206+
actors := createActors(actorsCount, onStart, onStop)
207+
208+
a := Combine(actors...).WithOptions().Build()
209+
210+
a.Start()
211+
drainC(onStartC, actorsCount)
212+
213+
// stop actors indiviually, and expect that after some time
214+
// there wont be any other actors stopping.
215+
stopCount := i + 1
216+
for j := range stopCount {
217+
actors[j].Stop()
218+
}
219+
220+
drainC(onStopC, stopCount)
221+
222+
select {
223+
case <-onStartC:
224+
t.Fatal("should not have any more stopped actors")
225+
case <-time.After(time.Millisecond * 20):
226+
}
227+
228+
a.Stop()
229+
drainC(onStopC, actorsCount-stopCount)
230+
}
231+
}
232+
186233
func Test_Combine_OptOnStop_AfterActorStops(t *testing.T) {
187234
t.Parallel()
188235

0 commit comments

Comments
 (0)