Add timeout error for influx
This adds a type to be returned when requests to InfluxDB were cancelled or timed out.pull/53/head
parent
a8291c602c
commit
d3da914994
|
@ -0,0 +1,13 @@
|
|||
package influx
|
||||
|
||||
const (
|
||||
ErrTimedOut string = "Timeout during request to InfluxDB"
|
||||
)
|
||||
|
||||
// TimeoutError is returned when requests to InfluxDB are cancelled or time
|
||||
// out.
|
||||
type TimeoutError struct{}
|
||||
|
||||
func (te TimeoutError) Error() string {
|
||||
return ErrTimedOut
|
||||
}
|
|
@ -43,6 +43,6 @@ func (c *Client) Query(ctx context.Context, query mrfusion.Query) (mrfusion.Resp
|
|||
case resp := <-resps:
|
||||
return resp, resp.err
|
||||
case <-ctx.Done():
|
||||
return nil, nil
|
||||
return nil, TimeoutError{}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,10 @@ func Test_Influx_CancelsInFlightRequests(t *testing.T) {
|
|||
series, _ := influx.NewClient(ts.URL)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
errs := make(chan (error))
|
||||
go func() {
|
||||
_, _ = series.Query(ctx, "show databases")
|
||||
_, err := series.Query(ctx, "show databases")
|
||||
errs <- err
|
||||
}()
|
||||
|
||||
cancel()
|
||||
|
@ -75,4 +77,9 @@ func Test_Influx_CancelsInFlightRequests(t *testing.T) {
|
|||
if started != true && finished != false {
|
||||
t.Errorf("Expected cancellation during request processing. Started: %t. Finished: %t", started, finished)
|
||||
}
|
||||
|
||||
err := <-errs
|
||||
if _, ok := err.(influx.TimeoutError); !ok {
|
||||
t.Error("Expected TimeoutError but wasn't. err was", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue