MCPcopy Index your code
hub / github.com/ContentSquare/chproxy / TestQueryWithRetryFail

Function TestQueryWithRetryFail

proxyretry_test.go:38–77  ·  view source on GitHub ↗

TestQueryWithRetryFail function statResponseWriter's statusCode will not be 200, but the query has been proxied The request will be retried 1 time with a different host in the same replica

(t *testing.T)

Source from the content-addressed store, hash-verified

36// TestQueryWithRetryFail function statResponseWriter's statusCode will not be 200, but the query has been proxied
37// The request will be retried 1 time with a different host in the same replica
38func TestQueryWithRetryFail(t *testing.T) {
39 body := "foo query"
40
41 req := newRequest("http://localhost:8080", body)
42
43 mhs := &mockHosts{
44 t: t,
45 b: body,
46 hs: []string{"localhost:8080", "localhost:8081"},
47 }
48
49 s := newMockScope(mhs.hs)
50
51 srw := mockStatRW(s)
52
53 mrw := &mockResponseWriterWithCode{
54 statusCode: 0,
55 }
56
57 retryNum := 1
58
59 _, err := executeWithRetry(
60 context.Background(),
61 s,
62 retryNum,
63 mhs.mockReverseProxy,
64 mrw,
65 srw,
66 req,
67 func(f float64) {},
68 func(l prometheus.Labels) {},
69 )
70
71 if err != nil {
72 t.Errorf("the execution with retry failed: %v", err)
73 }
74 assert.Equal(t, srw.statusCode, http.StatusBadGateway)
75 assert.Equal(t, mhs.hs, mhs.hst)
76
77}
78
79// TestRunQuerySuccessOnce function statResponseWriter's statusCode will be StatusOK after executeWithRetry, the query has been proxied
80// The execution will succeeded without retry

Callers

nothing calls this directly

Calls 4

newRequestFunction · 0.85
newMockScopeFunction · 0.85
mockStatRWFunction · 0.85
executeWithRetryFunction · 0.85

Tested by

no test coverage detected