mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 14:17:12 +02:00
Fix flaky TestReadClient/timeout test
Signed-off-by: Patryk Prus <p@trykpr.us>
This commit is contained in:
parent
d77d2a2d31
commit
ebeeb1c823
@ -332,9 +332,9 @@ func TestReadClient(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "timeout",
|
name: "timeout",
|
||||||
httpHandler: sampledResponseHTTPHandler(t),
|
httpHandler: delayedResponseHTTPHandler(t, 15*time.Millisecond),
|
||||||
timeout: time.Nanosecond,
|
timeout: 5 * time.Millisecond,
|
||||||
expectedErrorContains: "context deadline exceeded: request timed out after 1ns",
|
expectedErrorContains: "context deadline exceeded: request timed out after 5ms",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,3 +448,16 @@ func sampledResponseHTTPHandler(t *testing.T) http.HandlerFunc {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func delayedResponseHTTPHandler(t *testing.T, delay time.Duration) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
time.Sleep(delay)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/x-protobuf")
|
||||||
|
b, err := proto.Marshal(&prompb.ReadResponse{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = w.Write(snappy.Encode(nil, b))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user