Skip to content

Commit

Permalink
[eclipse-kanto#44] Now the test waits some time for the connection st…
Browse files Browse the repository at this point in the history
…atus to be updated

Signed-off-by: Nikola Zhechev <Nikola.Zhechev@bosch.io>
  • Loading branch information
nzhechev-bosch committed Sep 20, 2022
1 parent 9ba02b0 commit 9b29032
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions integration/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 9b29032

Please sign in to comment.