-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsend_info_test.go
65 lines (54 loc) · 1.45 KB
/
send_info_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
package secureio
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSendInfo_SendID(t *testing.T) {
assert.Equal(t, uint64(1), (&SendInfo{sendID: 1}).SendID())
}
func TestSendInfoPool_positive(t *testing.T) {
pool := newSendInfoPool(nil)
sendInfo := pool.AcquireSendInfo(context.Background())
close(sendInfo.c)
sendInfo.Release()
}
func TestSendInfoPool_releaseNonClosed(t *testing.T) {
defer func() {
err := recover()
assert.NotNil(t, err)
}()
pool := newSendInfoPool(nil)
sendInfo := pool.AcquireSendInfo(context.Background())
sendInfo.Release()
}
func TestSendInfoPool_releaseNonBusy(t *testing.T) {
defer func() {
err := recover()
assert.NotNil(t, err)
}()
pool := newSendInfoPool(nil)
sendInfo := pool.AcquireSendInfo(context.Background())
close(sendInfo.c)
sendInfo.isBusy = false
sendInfo.Release()
}
func TestSendInfoPool_acquireBusy(t *testing.T) {
defer func() {
err := recover()
assert.NotNil(t, err)
}()
pool := newSendInfoPool(nil)
sendInfo := pool.AcquireSendInfo(context.Background())
close(sendInfo.c)
sendInfo.Release()
sendInfo.isBusy = true
pool.AcquireSendInfo(context.Background())
}
func TestSendInfo_String(t *testing.T) {
pool := newSendInfoPool(nil)
sendInfo0 := pool.AcquireSendInfo(context.Background())
sendInfo1 := pool.AcquireSendInfo(context.Background())
assert.Equal(t, sendInfo0.String(), sendInfo0.String())
assert.NotEqual(t, sendInfo0.String(), sendInfo1.String())
}