MCPcopy Create free account
hub / github.com/zalando/skipper / TestClientTimeout

Function TestClientTimeout

proxy/clienttimeout_test.go:14–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestClientTimeout(t *testing.T) {
15 testLog := NewTestLog()
16 defer testLog.Close()
17
18 d := 200 * time.Millisecond
19
20 payload := []byte("backend reply")
21 backend := startTestServer(payload, 0, func(r *http.Request) {
22 time.Sleep(2 * d)
23 })
24
25 defer backend.Close()
26
27 doc := fmt.Sprintf(`hello: * -> "%s"`, backend.URL)
28 tp, err := newTestProxy(doc, FlagsNone)
29 if err != nil {
30 t.Error()
31 return
32 }
33
34 ps := httptest.NewServer(tp.proxy)
35 defer func() {
36 ps.Close()
37 tp.close()
38 }()
39
40 req, err := http.NewRequest("GET", ps.URL, nil)
41 if err != nil {
42 t.Errorf("Failed to create request: %v", err)
43 }
44
45 rsp, err := (&http.Client{
46 Timeout: d,
47 }).Do(req)
48
49 if err == nil {
50 t.Error("err should not be nil")
51 }
52 if rsp != nil {
53 t.Error("response should be nil")
54 }
55
56 const msgErrClientTimeout = "context canceled"
57 if err = testLog.WaitFor(msgErrClientTimeout, 3*d); err != nil {
58 t.Errorf("log should contain '%s'", msgErrClientTimeout)
59 }
60 const msgErrClientCanceledAfter = "client canceled after"
61 if err = testLog.WaitFor(msgErrClientCanceledAfter, 3*d); err != nil {
62 t.Errorf("log should contain '%s'", msgErrClientCanceledAfter)
63 }
64}
65
66func TestClientCancellation(t *testing.T) {
67 testLog := NewTestLog()

Callers

nothing calls this directly

Calls 9

newTestProxyFunction · 0.85
NewTestLogFunction · 0.70
startTestServerFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.65
ErrorfMethod · 0.65
DoMethod · 0.65
closeMethod · 0.45
WaitForMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…