forked from phuslu/log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
async_test.go
50 lines (46 loc) · 1010 Bytes
/
async_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
package log
import (
"io"
"os"
"testing"
)
func TestAsyncWriterZero(t *testing.T) {
w := &AsyncWriter{
ChannelSize: 0,
Writer: IOWriter{os.Stderr},
}
for i := 0; i < 10; i++ {
_, _ = wlprintf(w, InfoLevel, "%s, %d during async writer 1k buff size\n", timeNow(), i)
}
if err := w.Close(); err != nil {
t.Errorf("async close error: %+v", err)
}
}
func TestAsyncWriterSmall(t *testing.T) {
w := &AsyncWriter{
ChannelSize: 5,
Writer: IOWriter{os.Stderr},
}
for i := 0; i < 10; i++ {
_, _ = wlprintf(w, InfoLevel, "%s, %d during async writer 1k buff size\n", timeNow(), i)
}
if err := w.Close(); err != nil {
t.Errorf("async close error: %+v", err)
}
}
func BenchmarkAsyncWriter(b *testing.B) {
logger := Logger{
Writer: &AsyncWriter{
ChannelSize: 100,
Writer: IOWriter{io.Discard},
},
}
b.SetParallelism(1000)
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(b *testing.PB) {
for b.Next() {
logger.Info().Msg("hello async writer")
}
})
}