waitForRateLimit checks the current rate limit and waits if necessary. It ensures we have at least minRateLimitRemaining requests available before proceeding.
(t *testing.T)
| 82 | // waitForRateLimit checks the current rate limit and waits if necessary. |
| 83 | // It ensures we have at least minRateLimitRemaining requests available before proceeding. |
| 84 | func waitForRateLimit(t *testing.T) { |
| 85 | rateLimitMu.Lock() |
| 86 | defer rateLimitMu.Unlock() |
| 87 | |
| 88 | ghClient := getRESTClient(t) |
| 89 | ctx := context.Background() |
| 90 | |
| 91 | rateLimits, _, err := ghClient.RateLimit.Get(ctx) |
| 92 | if err != nil { |
| 93 | t.Logf("Warning: failed to check rate limit: %v", err) |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | core := rateLimits.Core |
| 98 | if core.Remaining < minRateLimitRemaining { |
| 99 | waitDuration := time.Until(core.Reset.Time) + time.Second // Add 1 second buffer |
| 100 | if waitDuration > 0 { |
| 101 | t.Logf("Rate limit low (%d/%d remaining). Waiting %v until reset...", |
| 102 | core.Remaining, core.Limit, waitDuration.Round(time.Second)) |
| 103 | time.Sleep(waitDuration) |
| 104 | t.Log("Rate limit reset, continuing...") |
| 105 | } |
| 106 | } else { |
| 107 | t.Logf("Rate limit OK: %d/%d remaining (reset in %v)", |
| 108 | core.Remaining, core.Limit, time.Until(core.Reset.Time).Round(time.Second)) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // ensureDockerImageBuilt makes sure the Docker image is built only once across all tests |
| 113 | func ensureDockerImageBuilt(t *testing.T) { |
no test coverage detected