forked from simonmittag/j8a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpclient_test.go
91 lines (82 loc) · 2.25 KB
/
httpclient_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package jabba
import (
"os"
"testing"
"time"
)
func TestHttpClientSocketTimeout(t *testing.T) {
Runner = &Runtime{
Config: Config{
Connection: Connection{
Upstream: Upstream{
SocketTimeoutSeconds: 1,
},
},
},
}
client := scaffoldHTTPClient(*Runner)
start := time.Now()
_, err := client.Get("http://10.73.124.255:2/uri")
elapsed := time.Since(start)
want := time.Duration(1 * time.Second)
if elapsed < want {
t.Errorf("socket timeout was not respected, client aborted too early, wanted > %v, got %v", want, elapsed)
}
if err == nil {
t.Errorf("uh oh http client not meant to resolve got no error for non existing URL")
}
}
//TestDefaultDownstreamReadTimeout
func TestGetTcpCntAndKeepAliveIntervalDuration(t *testing.T) {
Runner = &Runtime{
Config: Config{
Connection: Connection{
Upstream: Upstream{
IdleTimeoutSeconds: 120,
},
},
},
}
os.Setenv("OS", "linux")
got := getTCPKeepCnt()
want := 9
if got != want {
t.Errorf("incorrect linux tcp cnt interval for socket timeout test, got %v, want %v", got, want)
}
gotKeepAlive := getKeepAliveIntervalDuration().Nanoseconds()
//nanos for keepAlive interval
wantKeepAlive := int64(120 / float64(got) * 1000000000)
if gotKeepAlive != wantKeepAlive {
t.Errorf("incorrect linux keepalive interval duration, got %v, want %v", gotKeepAlive, wantKeepAlive)
}
os.Setenv("OS", "windows")
got = getTCPKeepCnt()
want = 5
if got != want {
t.Errorf("incorrect windows tcp cnt interval for socket timeout test, got %v, want %v", got, want)
}
os.Setenv("OS", "darwin")
got = getTCPKeepCnt()
want = 8
if got != want {
t.Errorf("incorrect darwin tcp cnt interval for socket timeout test, got %v, want %v", got, want)
}
os.Setenv("OS", "freebsd")
got = getTCPKeepCnt()
want = 8
if got != want {
t.Errorf("incorrect freebsd tcp cnt interval for socket timeout test, got %v, want %v", got, want)
}
os.Setenv("OS", "openbsd")
got = getTCPKeepCnt()
want = 8
if got != want {
t.Errorf("incorrect openbsd tcp cnt interval for socket timeout test, got %v, want %v", got, want)
}
os.Setenv("OS", "alpine")
got = getTCPKeepCnt()
want = 9
if got != want {
t.Errorf("incorrect other linux tcp cnt interval for socket timeout test, got %v, want %v", got, want)
}
}