-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbind_std_linux_test.go
More file actions
92 lines (78 loc) · 2.22 KB
/
Copy pathbind_std_linux_test.go
File metadata and controls
92 lines (78 loc) · 2.22 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//go:build linux
package conn
import (
"testing"
"github.com/asciimoth/gonnect"
"golang.org/x/net/ipv6"
)
type recordingBatchReader struct {
readLens []int
}
func (r *recordingBatchReader) ReadBatch(msgs []ipv6.Message, _ int) (int, error) {
r.readLens = append(r.readLens, len(msgs))
return 0, nil
}
func TestStdNetBindReceiveUsesConfiguredReadBatchSize(t *testing.T) {
const batchSize = 3
bind := NewStdNetBindWithOptions((&gonnect.NativeConfig{}).Build(), StdNetBindOptions{
BatchSize: batchSize,
}).(*StdNetBind)
br := &recordingBatchReader{}
bufs := make([][]byte, batchSize+2)
for i := range bufs {
bufs[i] = make([]byte, 128)
}
sizes := make([]int, batchSize+2)
eps := make([]Endpoint, batchSize+2)
n, err := bind.receiveIP(br, nil, false, bufs, sizes, eps)
if err != nil {
t.Fatalf("receiveIP() err = %v", err)
}
if n != 0 {
t.Fatalf("receiveIP() n = %d, want 0", n)
}
if got := br.readLens; len(got) != 1 || got[0] != batchSize {
t.Fatalf("ReadBatch lens = %v, want [%d]", got, batchSize)
}
}
func TestStdNetBindReceiveGROUsesConfiguredReadBatchWindow(t *testing.T) {
const batchSize = 65
bind := NewStdNetBindWithOptions((&gonnect.NativeConfig{}).Build(), StdNetBindOptions{
BatchSize: batchSize,
}).(*StdNetBind)
br := &recordingBatchReader{}
bufs := make([][]byte, batchSize)
for i := range bufs {
bufs[i] = make([]byte, 128)
}
sizes := make([]int, batchSize)
eps := make([]Endpoint, batchSize)
n, err := bind.receiveIP(br, nil, true, bufs, sizes, eps)
if err != nil {
t.Fatalf("receiveIP() err = %v", err)
}
if n != 0 {
t.Fatalf("receiveIP() n = %d, want 0", n)
}
if got := br.readLens; len(got) != 1 || got[0] != 2 {
t.Fatalf("ReadBatch lens = %v, want [2]", got)
}
}
func TestGroReadBatchSize(t *testing.T) {
cases := []struct {
batchSize int
want int
}{
{batchSize: 1, want: 1},
{batchSize: 2, want: 1},
{batchSize: udpSegmentMaxDatagrams, want: 1},
{batchSize: udpSegmentMaxDatagrams + 1, want: 2},
{batchSize: IdealBatchSize, want: 2},
}
for _, tt := range cases {
if got := groReadBatchSize(tt.batchSize); got != tt.want {
t.Fatalf("groReadBatchSize(%d) = %d, want %d", tt.batchSize, got, tt.want)
}
}
}
var _ batchReader = (*recordingBatchReader)(nil)