mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-17 16:16:37 +00:00
Fix test_get_repo_info
: Retry on rate limit
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
6e0f9cd6da
commit
999ebb964c
1 changed files with 16 additions and 29 deletions
|
@ -535,49 +535,36 @@ mod test {
|
||||||
let mut tests: Vec<(_, _)> = Vec::new();
|
let mut tests: Vec<(_, _)> = Vec::new();
|
||||||
|
|
||||||
for client in create_client() {
|
for client in create_client() {
|
||||||
for repo in PUBLIC_REPOS {
|
let spawn_get_repo_info_task = |repo| {
|
||||||
let client = client.clone();
|
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((
|
tests.push((
|
||||||
Some(RepoInfo::new(repo.clone(), false)),
|
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 {
|
for repo in NON_EXISTENT_REPOS {
|
||||||
let client = client.clone();
|
tests.push((None, spawn_get_repo_info_task(repo)));
|
||||||
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if client.has_gh_token() {
|
if client.has_gh_token() {
|
||||||
for repo in PRIVATE_REPOS {
|
for repo in PRIVATE_REPOS {
|
||||||
let client = client.clone();
|
|
||||||
|
|
||||||
tests.push((
|
tests.push((
|
||||||
Some(RepoInfo::new(repo.clone(), true)),
|
Some(RepoInfo::new(repo.clone(), true)),
|
||||||
tokio::spawn(async move {
|
spawn_get_repo_info_task(repo),
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue