-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflush_test.go
63 lines (48 loc) · 1.06 KB
/
flush_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
62
63
package mtsdb
import (
"context"
"github.com/stretchr/testify/require"
"sync/atomic"
"testing"
"time"
)
func TestFlush(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.Flush()
m.wg.Wait()
assert.Equal(uint64(4), insertInc.Load())
_ = c.Inc("one")
_ = c.Inc("one")
checkOne, _ := c.Get("one")
assert.Equal(uint32(2), checkOne)
_, ok := c.Get("two")
assert.False(ok)
_ = m.Close()
}