Skip to content

Commit

Permalink
fix: increase concurrency in tests to avoid OS performance differences
Browse files Browse the repository at this point in the history
  • Loading branch information
peterlgh7 committed Jun 15, 2023
1 parent 30f8171 commit 5846027
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ func TestFilter(t *testing.T) {
t.Run("Concurrency yields reduced processing times", func(t *testing.T) {
pipeline := jpipe.New(context.TODO())
start := time.Now()
channel := jpipe.FromSlice(pipeline, []int{1, 2, 3, 4, 5}).
channel := jpipe.FromSlice(pipeline, []int{1, 2, 3, 4, 5, 6, 7, 8}).
Filter(func(i int) bool {
time.Sleep(10 * time.Millisecond)
return i%2 == 1
}, jpipe.Concurrent(3))
}, jpipe.Concurrent(4))

mappedValues := drainChannel(channel)
elapsed := time.Since(start)

slices.Sort(mappedValues) // The output order with concurrency is unpredictable
assert.Equal(t, []int{1, 3, 5}, mappedValues)
assert.Less(t, elapsed, 30*time.Millisecond) // It would have taken 50ms serially, but it takes about 20ms with 5 elements and concurrency 3
assert.Equal(t, []int{1, 3, 5, 7}, mappedValues)
assert.Less(t, elapsed, 40*time.Millisecond) // It would have taken 80ms serially, but it takes about 20ms with 8 elements and concurrency 4
assertPipelineDone(t, pipeline, 10*time.Millisecond)
})

Expand Down

0 comments on commit 5846027

Please sign in to comment.