Skip to content

Commit

Permalink
simplify timer
Browse files Browse the repository at this point in the history
  • Loading branch information
dovholuknf committed Nov 15, 2024
1 parent 1c676c5 commit c683dac
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions ziti/cmd/edge/quickstart_shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,20 @@ func getIdentityByName(client *rest_management_api_client.ZitiEdgeManagement, na
}
params.SetTimeout(30 * time.Second)

var resp *identity.ListIdentitiesOK
var err error

timeout := time.After(3 * time.Second)
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
timeout := time.Now().Add(3 * time.Second)

for {
select {
case <-timeout:
log.Errorf("Could not obtain an ID for the identity named %s after retries", name)
return nil // Return nil if you don't want to panic on failure
case <-ticker.C:
resp, err = client.Identity.ListIdentities(params, nil)
if err == nil && len(resp.GetPayload().Data) > 0 {
return resp.GetPayload().Data[0]
}
// Log and retry
fmt.Printf("Retrying to fetch identity %s...\n", name)
resp, err := client.Identity.ListIdentities(params, nil)
if err == nil && len(resp.GetPayload().Data) > 0 {
return resp.GetPayload().Data[0]
}

if time.Now().After(timeout) {
log.Fatalf("Could not obtain an ID for the identity named %s after retries", name)
return nil
}

time.Sleep(100 * time.Millisecond)
}
}

Expand Down

0 comments on commit c683dac

Please sign in to comment.