address review comments

- Cancel discarded response bodies before retrying so the underlying
  connection can be returned to the pool instead of being held open
  until the response is garbage collected.
- Stop asserting on the rejected error message in the network-error
  retry test; track rejection via a flag so the test isn't tied to
  fetch/MSW error strings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
This commit is contained in:
Fredrik Adelöw
2026-05-04 11:01:41 +02:00
parent 6b112d3fe8
commit 90d3968e6c
2 changed files with 10 additions and 6 deletions
@@ -370,15 +370,15 @@ describe('GitLabIntegration', () => {
// Attach the catch handler before advancing timers so the in-flight
// rejections don't surface as unhandled.
const caught = integration
.fetch('https://h.com/api/v4')
.catch((e: unknown) => e);
let didReject = false;
const settled = integration.fetch('https://h.com/api/v4').catch(() => {
didReject = true;
});
await jest.advanceTimersByTimeAsync(100);
await jest.advanceTimersByTimeAsync(200);
const error = await caught;
await settled;
expect(error).toBeTruthy();
expect(String(error)).toMatch(/fetch/i);
expect(didReject).toBe(true);
expect(callCount).toBe(3); // initial + 2 retries
});
});
@@ -140,6 +140,10 @@ export class GitLabIntegration implements ScmIntegration {
? parseInt(retryAfter, 10) * 1000
: Math.min(100 * Math.pow(2, attempt - 1), 10000); // Exponential backoff, cap at 10 seconds
// Release the underlying connection so it can be reused, since we're
// about to discard this response in favor of a retry.
await response?.body?.cancel().catch(() => {});
await sleep(delay, abortSignal);
}
};