-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathbatch_processor_test.go
More file actions
49 lines (40 loc) · 996 Bytes
/
batch_processor_test.go
File metadata and controls
49 lines (40 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package sentry
import (
"sync"
"testing"
"time"
)
func TestBatchProcessor_TimerStartsOnFirstItem(t *testing.T) {
var mu sync.Mutex
var batches [][]int
sendBatch := func(items []int) {
mu.Lock()
defer mu.Unlock()
batch := make([]int, len(items))
copy(batch, items)
batches = append(batches, batch)
}
processor := newBatchProcessor(sendBatch).WithBatchTimeout(50 * time.Millisecond)
processor.Start()
defer processor.Shutdown()
time.Sleep(100 * time.Millisecond)
mu.Lock()
if len(batches) != 0 {
mu.Unlock()
t.Fatalf("expected 0 batches before adding items, got %d", len(batches))
}
mu.Unlock()
processor.Send(42)
time.Sleep(100 * time.Millisecond)
mu.Lock()
defer mu.Unlock()
if len(batches) != 1 {
t.Fatalf("expected 1 batch after timeout, got %d", len(batches))
}
if len(batches[0]) != 1 {
t.Fatalf("expected 1 item in batch, got %d", len(batches[0]))
}
if batches[0][0] != 42 {
t.Errorf("expected item value 42, got %d", batches[0][0])
}
}