Skip to content

Commit

Permalink
combine: add Test_Combine_OthersNotStopped
Browse files Browse the repository at this point in the history
  • Loading branch information
vladopajic committed Jan 31, 2025
1 parent 6355bd2 commit af7094e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions actor/combine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"sync/atomic"
"testing"
"time"

"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -183,6 +184,52 @@ func testCombineOptStopTogether(t *testing.T, actorsCount int) {
}
}

// Test_Combine_OthersNotStopped asserts that if any of underlaying
// actors end it wont affect other actors. This is default behavior when
// `OptStopTogether` is not provided.
func Test_Combine_OthersNotStopped(t *testing.T) {
t.Parallel()

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

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

for i := range actorsCount {
onStartC := make(chan any, actorsCount)
onStopC := make(chan any, actorsCount)
onStart := OptOnStart(func(Context) { onStartC <- `🌞` })
onStop := OptOnStop(func() { onStopC <- `🌚` })
actors := createActors(actorsCount, onStart, onStop)

a := Combine(actors...).WithOptions().Build()

a.Start()
drainC(onStartC, actorsCount)

// stop actors indiviually, and expect that after some time
// there wont be any other actors stopping.
stopCount := i + 1
for j := range stopCount {
actors[j].Stop()
}

drainC(onStopC, stopCount)

select {
case <-onStartC:
t.Fatal("should not have any more stopped actors")
case <-time.After(time.Millisecond * 20):
}

a.Stop()
drainC(onStopC, actorsCount-stopCount)
}
}

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

Expand Down

0 comments on commit af7094e

Please sign in to comment.