Skip to content

Commit

Permalink
adding test with interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Jun 22, 2023
1 parent 60f54e5 commit 6c3f22b
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion batcher/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package batcher

import (
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestBatcher(t *testing.T) {
func TestBatcherStandard(t *testing.T) {
var (
batchSize = 100
wanted = 100000
Expand Down Expand Up @@ -38,3 +39,38 @@ func TestBatcher(t *testing.T) {
require.Equal(t, wanted, got)
require.True(t, minWantedBatches <= gotBatches)
}

func TestBatcherWithInterval(t *testing.T) {
var (
batchSize = 200
wanted = 1000
minWantedBatches = 10
got int
gotBatches int
)
callback := func(t []int) {
gotBatches++
for range t {
got++
}
}
bat := New[int](
WithMaxCapacity[int](batchSize),
WithFlushCallback[int](callback),
WithFlushInterval[int](10*time.Millisecond),
)

bat.Run()

for i := 0; i < wanted; i++ {
time.Sleep(2 * time.Millisecond)
bat.Append(i)
}

bat.Stop()

bat.WaitDone()

require.Equal(t, wanted, got)
require.True(t, minWantedBatches <= gotBatches)
}

0 comments on commit 6c3f22b

Please sign in to comment.