-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhttpclient_test.go
102 lines (92 loc) · 2.54 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
92
93
94
95
96
97
98
99
100
101
102
package j8a
import (
"os"
"runtime"
"testing"
"time"
)
func TestHttpClientSocketTimeout(t *testing.T) {
//aaaarggghhh this test doesn't run on macOS but we need it on linux
if runtime.GOOS == "darwin" {
return
}
Runner = &Runtime{
Config: Config{
Connection: Connection{
Upstream: Upstream{
SocketTimeoutSeconds: 3,
},
},
},
Start: time.Now(),
ConnectionWatcher: ConnectionWatcher{dwnOpenConns: 0},
}
Runner.initReloadableCert()
client := scaffoldHTTPClient(Runner)
start := time.Now()
_, err := client.Get("http://10.73.124.255:8089/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,
},
},
},
Start: time.Now(),
}
Runner.initReloadableCert()
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)
}
}