From 0c4e17406d58c928f798d6de3ce4cb7a862084cc Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Fri, 19 Jan 2018 04:37:46 +0100 Subject: [PATCH] [TASK] influxdb ping on startup --- database/influxdb/database.go | 9 +++++++-- database/influxdb/database_test.go | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/database/influxdb/database.go b/database/influxdb/database.go index a0de00c..0266b62 100644 --- a/database/influxdb/database.go +++ b/database/influxdb/database.go @@ -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) diff --git a/database/influxdb/database_test.go b/database/influxdb/database_test.go index 5c2598c..9a7e8aa 100644 --- a/database/influxdb/database_test.go +++ b/database/influxdb/database_test.go @@ -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) }