Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: return non-nil error when device does not become active #339

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading