forked from obsidiandynamics/goharvest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattery_test.go
43 lines (35 loc) · 903 Bytes
/
battery_test.go
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
package goharvest
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEnqueue_concurrencyOf1(t *testing.T) {
enqueued := make(chan OutboxRecord)
b := newConcurrentBattery(1, 0, func(records chan OutboxRecord) {
for rec := range records {
enqueued <- rec
}
})
defer b.shutdown()
rec := OutboxRecord{}
assert.True(t, b.enqueue(rec))
assert.Equal(t, rec, <-enqueued)
}
func TestEnqueue_concurrencyOf2(t *testing.T) {
enqueued := make(chan OutboxRecord)
b := newConcurrentBattery(2, 0, func(records chan OutboxRecord) {
for rec := range records {
enqueued <- rec
}
})
defer b.shutdown()
rec := OutboxRecord{}
assert.True(t, b.enqueue(rec))
assert.Equal(t, rec, <-enqueued)
}
func TestEnqueue_afterDone(t *testing.T) {
b := newConcurrentBattery(2, 0, func(records chan OutboxRecord) {})
b.await()
assert.False(t, b.enqueue(OutboxRecord{}))
b.stop()
}