Fixing merge conflict.
commit
202e420e91
|
@ -8,6 +8,7 @@
|
|||
- [2687](https://github.com/influxdb/influxdb/issues/2687): Add batching support to Collectd inputs.
|
||||
- [2696](https://github.com/influxdb/influxdb/pull/2696): Add line protocol. This is now the preferred way to write data.
|
||||
- [2751](https://github.com/influxdb/influxdb/pull/2751): Add UDP input. UPD only supports the line protocol now.
|
||||
- [2684](https://github.com/influxdb/influxdb/pull/2684): Include client timeout configuration. Thanks @vladlopes!
|
||||
|
||||
### Bugfixes
|
||||
- [2776](https://github.com/influxdb/influxdb/issues/2776): Re-implement retention policy enforcement.
|
||||
|
|
|
@ -25,11 +25,13 @@ type Query struct {
|
|||
// URL: The URL of the server connecting to.
|
||||
// Username/Password are optional. They will be passed via basic auth if provided.
|
||||
// UserAgent: If not provided, will default "InfluxDBClient",
|
||||
// Timeout: If not provided, will default to 0 (no timeout)
|
||||
type Config struct {
|
||||
URL url.URL
|
||||
Username string
|
||||
Password string
|
||||
UserAgent string
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// Client is used to make calls to the server.
|
||||
|
@ -54,7 +56,7 @@ func NewClient(c Config) (*Client, error) {
|
|||
url: c.URL,
|
||||
username: c.Username,
|
||||
password: c.Password,
|
||||
httpClient: http.DefaultClient,
|
||||
httpClient: &http.Client{Timeout: c.Timeout},
|
||||
userAgent: c.UserAgent,
|
||||
}
|
||||
if client.userAgent == "" {
|
||||
|
|
|
@ -496,3 +496,35 @@ func TestBatchPoints_Normal(t *testing.T) {
|
|||
t.Errorf("unable to unmarshal nanosecond data: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_Timeout(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(1 * time.Second)
|
||||
var data influxdb.Response
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_ = json.NewEncoder(w).Encode(data)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
u, _ := url.Parse(ts.URL)
|
||||
config := client.Config{URL: *u, Timeout: 500 * time.Millisecond}
|
||||
c, err := client.NewClient(config)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error. expected %v, actual %v", nil, err)
|
||||
}
|
||||
|
||||
query := client.Query{}
|
||||
_, err = c.Query(query)
|
||||
if err == nil {
|
||||
t.Fatalf("unexpected success. expected timeout error")
|
||||
} else if !strings.Contains(err.Error(), "use of closed network connection") {
|
||||
t.Fatalf("unexpected error. expected 'use of closed network connection' error, got %v", err)
|
||||
}
|
||||
|
||||
confignotimeout := client.Config{URL: *u}
|
||||
cnotimeout, err := client.NewClient(confignotimeout)
|
||||
_, err = cnotimeout.Query(query)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error. expected %v, actual %v", nil, err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue