Skip to content

Commit

Permalink
test: return non-nil error when device does not become active
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Aug 31, 2023
1 parent c7eed25 commit 3a17205
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions test/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ func CreateTestDevice(projectId, name string) (string, error) {
}

func IsDeviceStateActive(deviceId string) (bool, error) {
var err error
var resp *openapiclient.Device
TestApiClient := TestClient()
predefinedTime := 500 * time.Second // Adjust this as needed
retryInterval := 10 * time.Second // Adjust this as needed
startTime := time.Now()
for time.Since(startTime) < predefinedTime {
resp, _, err = TestApiClient.DevicesApi.FindDeviceById(context.Background(), deviceId).Execute()
resp, _, err := TestApiClient.DevicesApi.FindDeviceById(context.Background(), deviceId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DevicesApi.FindDeviceById``: %v\n", err)
return false, err
Expand All @@ -71,7 +69,7 @@ func IsDeviceStateActive(deviceId string) (bool, error) {
// Sleep for the specified interval
time.Sleep(retryInterval)
}
return false, err
return false, fmt.Errorf("timed out waiting for device %v to become active", deviceId)
}

func StopTestDevice(deviceId string) error {
Expand Down

0 comments on commit 3a17205

Please sign in to comment.