From b5831b2137c8971689d79e220cfbb48898daabe3 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Mon, 10 Jun 2024 23:42:18 +1000 Subject: [PATCH] Add retry on rate limit in unit testing Signed-off-by: Jiahao XU --- crates/binstalk-git-repo-api/src/gh_api_client.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/binstalk-git-repo-api/src/gh_api_client.rs b/crates/binstalk-git-repo-api/src/gh_api_client.rs index 99fb92f0..c5750429 100644 --- a/crates/binstalk-git-repo-api/src/gh_api_client.rs +++ b/crates/binstalk-git-repo-api/src/gh_api_client.rs @@ -551,7 +551,16 @@ mod test { tests.push(( None, - tokio::spawn(async move { client.get_repo_info(&repo).await }), + tokio::spawn(async move { + loop { + match client.get_repo_info(&repo).await { + Err(GhApiError::RateLimit { retry_after }) => { + sleep(retry_after.unwrap_or(DEFAULT_RETRY_AFTER)).await + } + res => break res, + } + } + }), )); }