Skip to content

Commit 28dc4d2

Browse files
feature(streamwork): fix CircuitBreaker test
1 parent 8f6d698 commit 28dc4d2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

streamwork/circuitbreaker_test.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@ func TestCircuitBreaker(t *testing.T) {
1414

1515
cb := NewCircuitBreaker()
1616

17-
output, err := Stream2(
17+
output, err := Stream3(
1818
ctx, ReadSeq(
1919
func(yield func(int) bool) {
2020
for i := range 10 {
2121
if !yield(i) {
2222
return
2323
}
24-
runtime.Gosched() // allows the goroutines to receive all values already sent
25-
if i >= 5 {
26-
cb.Cut() // cutting the circuit breaker should close the stream and make the next yield return false
27-
}
28-
require.LessOrEqual(t, i, 5) // we should never get to the next value
2924
}
3025
},
3126
), CircuitBreakerWorker[int](cb),
27+
WorkerFunc(
28+
func(ctx context.Context, v int) int {
29+
if v >= 5 {
30+
cb.Cut() // cutting the circuit breaker should close the stream and make the next yield return false
31+
}
32+
return v
33+
},
34+
),
3235
)
3336
require.NoError(t, err)
3437
require.Equal(t, []int{0, 1, 2, 3, 4, 5}, output)

0 commit comments

Comments
 (0)