forked from rlmcpherson/s3gof3r
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pool_test.go
43 lines (37 loc) · 860 Bytes
/
pool_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 s3gof3r
import (
"bytes"
"log"
"strings"
"testing"
"time"
)
func TestBP(t *testing.T) {
// send log output to buffer
lf := *bytes.NewBuffer(nil)
SetLogger(&lf, "", log.LstdFlags, true)
bp := bufferPool(mb)
bp.timeout = 1 * time.Millisecond
b := <-bp.get
if cap(b) != int(mb) {
t.Errorf("Expected buffer capacity: %d. Actual: %d", kb, cap(b))
}
bp.give <- b
if bp.makes != 2 {
t.Errorf("Expected makes: %d. Actual: %d", 2, bp.makes)
}
b = <-bp.get
bp.give <- b
time.Sleep(2 * time.Millisecond)
if bp.makes != 3 {
t.Errorf("Expected makes: %d. Actual: %d", 3, bp.makes)
}
close(bp.quit)
expLog := "3 buffers of 1 MB allocated"
time.Sleep(1 * time.Millisecond) // wait for log
ls := lf.String()
if !strings.Contains(ls, expLog) {
t.Errorf("BP debug logging on quit: \nExpected: %s\nActual: %s",
expLog, ls)
}
}