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

Function TestKillQuery

proxy_test.go:874–931  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

872}
873
874func TestKillQuery(t *testing.T) {
875 testCases := []struct {
876 name string
877 f func(p *reverseProxy) *http.Response
878 }{
879 {
880 name: "timeout user",
881 f: func(p *reverseProxy) *http.Response {
882 p.users[defaultUsername].maxExecutionTime = time.Millisecond * 5
883 return makeHeavyRequest(p, time.Millisecond*40)
884 },
885 },
886 {
887 name: "timeout cluster user",
888 f: func(p *reverseProxy) *http.Response {
889 p.clusters["cluster"].users["web"].maxExecutionTime = time.Millisecond * 5
890 return makeHeavyRequest(p, time.Millisecond*40)
891 },
892 },
893 }
894
895 for _, tc := range testCases {
896 t.Run(tc.name, func(t *testing.T) {
897 proxy, err := getProxy(goodCfg)
898 if err != nil {
899 t.Fatalf("unexpected error: %s", err)
900 }
901 resp := tc.f(proxy)
902 b := bbToString(t, resp.Body)
903 id := extractID(scopeIDRe, b)
904 if len(id) == 0 {
905 t.Fatalf("expected Id to be extracted from %q", b)
906 }
907 // waiting btw 5 and 200 msec to get the answer from CHProxy
908 // because this code on github is unstable due to the poor performances
909 // of the server running the CI.
910 loop := true
911 counter := 0
912 for loop {
913 time.Sleep(time.Millisecond * 5)
914 counter++
915
916 _, err := registry.get(id)
917 if err == nil || counter > 40 {
918 loop = false
919 }
920 }
921
922 state, err := registry.get(id)
923 if err != nil {
924 t.Fatalf("unexpected requestRegistry err for key %q: %s", id, err)
925 }
926 if !state {
927 t.Fatalf("query expected to be killed; response: %s", b)
928 }
929 })
930 }
931}

Callers

nothing calls this directly

Calls 5

makeHeavyRequestFunction · 0.85
getProxyFunction · 0.85
bbToStringFunction · 0.85
extractIDFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected