-
Notifications
You must be signed in to change notification settings - Fork 43
/
report_test.go
70 lines (66 loc) · 1.53 KB
/
report_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
package main
import (
"testing"
"time"
)
func TestReport(t *testing.T) {
clients, err := NewClients([]string{
"noop://foo",
"noop://bar",
}, 1, 5*time.Second)
if err != nil {
t.Fatal(err)
}
r := report{Clients: clients}
r.init()
r.handle(Response{
client: clients[0],
ID: 1,
})
r.handle(Response{
client: clients[0],
ID: 2,
})
if got, want := r.requests, 2; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
if got, want := len(r.pendingResponses), 2; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
if got, want := r.completed, 0; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
r.handle(Response{
client: clients[1],
ID: 2,
})
if got, want := r.requests, 3; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
if got, want := len(r.pendingResponses), 1; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
if got, want := r.completed, 1; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
if got, want := r.mismatched, 0; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
r.handle(Response{
client: clients[1],
ID: 1,
Body: []byte("foo"),
})
if got, want := r.requests, 4; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
if got, want := len(r.pendingResponses), 0; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
if got, want := r.completed, 2; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
if got, want := r.mismatched, 1; got != want {
t.Errorf("got: %d; want: %d", got, want)
}
}