[TASK] influxdb ping on startup

This commit is contained in:
Martin Geno 2018-01-19 04:37:46 +01:00
parent 1464092a69
commit 0c4e17406d
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
2 changed files with 24 additions and 2 deletions

View File

@ -18,7 +18,7 @@ const (
CounterMeasurementFirmware = "firmware" // Measurement for firmware statistics
CounterMeasurementModel = "model" // Measurement for model statistics
CounterMeasurementAutoupdater = "autoupdater" // Measurement for autoupdater
batchMaxSize = 500
batchMaxSize = 1000
batchTimeout = 5 * time.Second
)
@ -69,10 +69,15 @@ func Connect(configuration map[string]interface{}) (database.Connection, error)
return nil, err
}
_, _, err = c.Ping(time.Millisecond * 50)
if err != nil {
return nil, err
}
db := &Connection{
config: config,
client: c,
points: make(chan *client.Point, 1000),
points: make(chan *client.Point, batchMaxSize),
}
db.wg.Add(1)

View File

@ -1,6 +1,8 @@
package influxdb
import (
"net/http"
"net/http/httptest"
"testing"
"time"
@ -27,6 +29,21 @@ func TestConnect(t *testing.T) {
"username": "",
"password": "",
})
assert.Nil(conn)
assert.Error(err)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
conn, err = Connect(map[string]interface{}{
"address": srv.URL,
"database": "",
"username": "",
"password": "",
})
assert.NotNil(conn)
assert.NoError(err)
}