-
Notifications
You must be signed in to change notification settings - Fork 0
/
close_test.go
61 lines (46 loc) · 1.03 KB
/
close_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package mtsdb
import (
"context"
"github.com/stretchr/testify/require"
"sync/atomic"
"testing"
"time"
)
func TestClose(t *testing.T) {
t.Parallel()
assert := require.New(t)
insertInc := atomic.Uint64{}
tstConfig := Config{
InsertDuration: 10 * time.Minute,
WorkerPoolSize: 0,
BatchInsertSize: 1000,
skipValidation: true,
}
ctx := context.Background()
m, err := newMtsdb(ctx, nil, tstConfig)
assert.NoError(err)
c, err := NewMetricCounter(ctx, "testCounter", MetricCounterConfig{}, "label1")
assert.NoError(err)
m.MustRegister(c)
go func() {
for job := range m.job {
insertInc.Add(uint64(job.Len()))
m.wg.Done()
}
}()
_ = c.Inc("one")
_ = c.Inc("two")
_ = c.Inc("three")
_ = c.Inc("four")
_ = c.Inc("three")
_ = c.Inc("four")
assert.Equal(uint64(0), insertInc.Load(), "bulk insert should not be called")
_ = m.Close()
assert.Equal(uint64(4), insertInc.Load())
_ = c.Inc("one")
value, ok := c.Get("one")
assert.True(ok)
assert.Equal(uint32(1), value)
_, ok = c.Get("two")
assert.False(ok)
}