-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflusher_test.go
74 lines (68 loc) · 1.66 KB
/
flusher_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
64
65
66
67
68
69
70
71
72
73
74
package qkit
import (
"fmt"
"math/rand"
"sync"
"sync/atomic"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
/*
Creation Time: 2021 - Jan - 01
Created by: (ehsan)
Maintainers:
1. Ehsan N. Moosa (E2)
Auditor: Ehsan N. Moosa (E2)
Copyright Ronak Software Group 2020
*/
func TestNewFlusherPool(t *testing.T) {
Convey("Flusher", t, func(c C) {
Convey("Without WaitTime", func(c C) {
var out, in int64
f := NewFlusherPool(10, 20, func(targetID string, entries []FlushEntry) {
time.Sleep(time.Millisecond * 100)
atomic.AddInt64(&out, int64(len(entries)))
})
wg := sync.WaitGroup{}
total := 10000
for i := 0; i < total; i++ {
wg.Add(1)
go func() {
f.EnterAndWait(fmt.Sprintf("T%d", rand.Intn(3)), NewEntry(rand.Intn(10)))
atomic.AddInt64(&in, 1)
wg.Done()
}()
}
wg.Wait()
for _, q := range f.pool {
c.So(q.entryChan, ShouldHaveLength, 0)
}
c.So(in, ShouldEqual, total)
c.So(out, ShouldEqual, total)
})
Convey("With WaitTime", func(c C) {
var out, in int64
f := NewFlusherPoolWithWaitTime(10, 20, 250*time.Millisecond, func(targetID string, entries []FlushEntry) {
time.Sleep(time.Millisecond * 100)
atomic.AddInt64(&out, int64(len(entries)))
})
wg := sync.WaitGroup{}
total := 10000
for i := 0; i < total; i++ {
wg.Add(1)
go func() {
f.EnterAndWait(fmt.Sprintf("T%d", rand.Intn(3)), NewEntry(rand.Intn(10)))
atomic.AddInt64(&in, 1)
wg.Done()
}()
}
wg.Wait()
for _, q := range f.pool {
c.So(q.entryChan, ShouldHaveLength, 0)
}
c.So(in, ShouldEqual, total)
c.So(out, ShouldEqual, total)
})
})
}