forked from nfx/slrp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshard_test.go
68 lines (57 loc) · 1.17 KB
/
shard_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
package pool
import (
"net/http"
"testing"
"time"
"github.com/nfx/slrp/app"
"github.com/stretchr/testify/assert"
)
func TestShardHandleReanimate(t *testing.T) {
now = func() time.Time {
return ti(0, 2, 0)
}
s := &shard{
Entries: []*entry{
{ReanimateAfter: ti(0, 1, 0)},
},
}
s.init(testPoolCfg, make(chan work))
s.minute = time.NewTicker(500 * time.Millisecond)
ctx := app.MockCtx()
defer ctx.Cancel()
go s.main(ctx)
<-ctx.Wait
assert.True(t, s.Entries[0].Ok)
}
func TestShardHandleReply(t *testing.T) {
now = func() time.Time {
return ti(0, 2, 0)
}
s := &shard{
Entries: []*entry{
{ReanimateAfter: ti(0, 1, 0)},
},
}
s.init(testPoolCfg, make(chan work))
ctx := app.MockCtx()
defer ctx.Cancel()
go s.main(ctx)
out := make(chan *http.Response)
s.reply <- reply{
r: request{
in: &http.Request{},
serial: 123,
out: out,
attempt: 10,
},
response: &http.Response{
StatusCode: 418,
Status: "I'm a teapot",
},
e: &entry{},
}
response := <-out
assert.Equal(t, 429, response.StatusCode)
assert.Equal(t, "123", response.Header.Get("X-Proxy-Serial"))
assert.Equal(t, "I'm a teapot", response.Status)
}