Skip to content

Commit

Permalink
Fix test_get_repo_info: Retry on rate limit
Browse files Browse the repository at this point in the history
Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Jun 10, 2024
1 parent 6e0f9cd commit 999ebb9
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions crates/binstalk-git-repo-api/src/gh_api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,49 +535,36 @@ mod test {
let mut tests: Vec<(_, _)> = Vec::new();

for client in create_client() {
for repo in PUBLIC_REPOS {
let spawn_get_repo_info_task = |repo| {
let client = client.clone();
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,
}
}
})
};

for repo in PUBLIC_REPOS {
tests.push((
Some(RepoInfo::new(repo.clone(), false)),
tokio::spawn(async move { client.get_repo_info(&repo).await }),
spawn_get_repo_info_task(repo),
));
}

for repo in NON_EXISTENT_REPOS {
let client = client.clone();

tests.push((
None,
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,
}
}
}),
));
tests.push((None, spawn_get_repo_info_task(repo)));
}

if client.has_gh_token() {
for repo in PRIVATE_REPOS {
let client = client.clone();

tests.push((
Some(RepoInfo::new(repo.clone(), true)),
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,
}
}
}),
spawn_get_repo_info_task(repo),
));
}
}
Expand Down

0 comments on commit 999ebb9

Please sign in to comment.