MCPcopy
hub / github.com/grafana/tempo / testSearchProgressShouldQuitAny

Function testSearchProgressShouldQuitAny

modules/frontend/combiner/search_test.go:27–82  ·  view source on GitHub ↗
(t *testing.T, marshalingFormat api.MarshallingFormat)

Source from the content-addressed store, hash-verified

25}
26
27func testSearchProgressShouldQuitAny(t *testing.T, marshalingFormat api.MarshallingFormat) {
28 // new combiner should not quit
29 c := NewSearch(0, false, marshalingFormat, false)
30 should := c.ShouldQuit()
31 require.False(t, should)
32
33 // 500 response should quit
34 c = NewSearch(0, false, marshalingFormat, false)
35 err := c.AddResponse(toHTTPResponseWithFormat(t, &tempopb.SearchResponse{}, 500, nil, marshalingFormat))
36 require.NoError(t, err)
37 should = c.ShouldQuit()
38 require.True(t, should)
39
40 // 429 response should quit
41 c = NewSearch(0, false, marshalingFormat, false)
42 err = c.AddResponse(toHTTPResponseWithFormat(t, &tempopb.SearchResponse{}, 429, nil, marshalingFormat))
43 require.NoError(t, err)
44 should = c.ShouldQuit()
45 require.True(t, should)
46
47 // unparseable body should not quit, but should return an error
48 c = NewSearch(0, false, marshalingFormat, false)
49 err = c.AddResponse(&testPipelineResponse{r: &http.Response{Body: io.NopCloser(strings.NewReader("foo")), StatusCode: 200}})
50 require.Error(t, err)
51 should = c.ShouldQuit()
52 require.False(t, should)
53
54 // under limit should not quit
55 c = NewSearch(2, false, marshalingFormat, false)
56 err = c.AddResponse(toHTTPResponseWithFormat(t, &tempopb.SearchResponse{
57 Traces: []*tempopb.TraceSearchMetadata{
58 {
59 TraceID: "1",
60 },
61 },
62 }, 200, nil, marshalingFormat))
63 require.NoError(t, err)
64 should = c.ShouldQuit()
65 require.False(t, should)
66
67 // over limit should quit
68 c = NewSearch(1, false, marshalingFormat, false)
69 err = c.AddResponse(toHTTPResponseWithFormat(t, &tempopb.SearchResponse{
70 Traces: []*tempopb.TraceSearchMetadata{
71 {
72 TraceID: "1",
73 },
74 {
75 TraceID: "2",
76 },
77 },
78 }, 200, nil, marshalingFormat))
79 require.NoError(t, err)
80 should = c.ShouldQuit()
81 require.True(t, should)
82}
83
84func TestSearchProgressShouldQuitMostRecentJSON(t *testing.T) {

Calls 5

NewSearchFunction · 0.85
toHTTPResponseWithFormatFunction · 0.85
ShouldQuitMethod · 0.65
AddResponseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected