Add coverage for bad hostnames and cancellation
The case where users passed bad hostnames to create new influx clients was untested as well as the cancellation logic.pull/10616/head
parent
f6ac18b692
commit
05dfabc06b
|
@ -45,6 +45,4 @@ func (c *Client) Query(ctx context.Context, query mrfusion.Query) (mrfusion.Resp
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,22 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/influxdata/mrfusion"
|
"github.com/influxdata/mrfusion"
|
||||||
"github.com/influxdata/mrfusion/influx"
|
"github.com/influxdata/mrfusion/influx"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_MakesRequestsToQueryEndpoint(t *testing.T) {
|
func Test_Influx_RejectsBadHostnames(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
_, err := influx.NewClient("wibble")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected an error for invalid influx host")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_Influx_MakesRequestsToQueryEndpoint(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
called := false
|
called := false
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -38,3 +47,32 @@ func Test_MakesRequestsToQueryEndpoint(t *testing.T) {
|
||||||
t.Error("Expected http request to Influx but there was none")
|
t.Error("Expected http request to Influx but there was none")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Influx_CancelsInFlightRequests(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
started := false
|
||||||
|
finished := false
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
started = true
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
finished = true
|
||||||
|
}))
|
||||||
|
defer func() {
|
||||||
|
ts.CloseClientConnections()
|
||||||
|
ts.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
series, _ := influx.NewClient(ts.URL)
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
_, _ = series.Query(ctx, "show databases")
|
||||||
|
}()
|
||||||
|
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
if started != true && finished != false {
|
||||||
|
t.Errorf("Expected cancellation during request processing. Started: %t. Finished: %t", started, finished)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue