diff --git a/integration/connector_test.go b/integration/connector_test.go index ca83ff1..7dc06f7 100644 --- a/integration/connector_test.go +++ b/integration/connector_test.go @@ -45,7 +45,8 @@ type testConfig struct { DittoUser string `def:"ditto"` DittoPassword string `def:"ditto"` - EventTimeoutMs int `def:"30000"` + EventTimeoutMs int `def:"30000"` + StatusTimeoutMs int `def:"10000"` TimeDeltaMs int `def:"5000"` } @@ -194,27 +195,45 @@ func TestConnectorSuite(t *testing.T) { } func (suite *ConnectorSuite) TestConnectionStatus() { - statusURL := fmt.Sprintf("%s/features/ConnectionStatus/properties/status", suite.thingURL) - body, err := suite.doRequest("GET", statusURL) - require.NoError(suite.T(), err, "connection status property should be available") - type connectionStatus struct { ReadySince time.Time `json:"readySince"` ReadyUntil time.Time `json:"readyUntil"` } - status := &connectionStatus{} - err = json.Unmarshal(body, status) - require.NoError(suite.T(), err, "connection status should be parsed") + timeout := time.Duration(suite.cfg.StatusTimeoutMS * int(time.Millisecond)) + threshold := time.Now().Add(timeout) + + for { + statusURL := fmt.Sprintf("%s/features/ConnectionStatus/properties/status", suite.thingURL) + body, err := suite.doRequest("GET", statusURL) + if err != nil { + if time.Now().Before(threshold) { + continue + } + suite.T().Errorf("connection status property not available: %v", err) + break + } + + status := &connectionStatus{} + err = json.Unmarshal(body, status) + require.NoError(suite.T(), err, "connection status should be parsed") - suite.T().Logf("%+v", status) - suite.T().Logf("current time: %v", time.Now()) + suite.T().Logf("%+v", status) + suite.T().Logf("current time: %v", time.Now()) - delta := int64(suite.cfg.TimeDeltaMs) - assert.Less(suite.T(), status.ReadySince.UnixMilli(), time.Now().UnixMilli()+delta, "readySince should be BEFORE current time") + forever := time.Date(9999, time.December, 31, 23, 59, 59, 0, time.UTC) + if status.ReadyUntil != forever { + if time.Now().Before(threshold) { + continue + } + suite.T().Errorf("readyUntil should be %v", forever) + break + } - forever := time.Date(9999, time.December, 31, 23, 59, 59, 0, time.UTC) - assert.Equal(suite.T(), status.ReadyUntil, forever, "readyUntil should be %v", forever) + delta := int64(suite.cfg.TimeDeltaMs) + assert.Less(suite.T(), status.ReadySince.UnixMilli(), time.Now().UnixMilli()+delta, "readySince should be BEFORE current time") + break + } } func (suite *ConnectorSuite) TestCommand() {