Parallelise test_get_repo_info

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-05-30 00:37:50 +10:00
parent 5f138e6655
commit 345255a65f
No known key found for this signature in database
GPG key ID: 76D1E687CA3C4928

View file

@ -450,41 +450,44 @@ mod test {
init_logger(); init_logger();
let mut tests: Vec<(_, _)> = Vec::new();
for client in create_client().await { for client in create_client().await {
eprintln!("In client {client:?}"); eprintln!("In client {client:?}");
for repo in PUBLIC_REPOS { for repo in PUBLIC_REPOS {
let res = client.get_repo_info(&repo).await; let client = client.clone();
if matches!(res, Err(GhApiError::RateLimit { .. })) { tests.push((
continue; Some(RepoInfo::new(repo.clone(), false)),
} tokio::spawn(async move { client.get_repo_info(&repo).await }),
));
assert_eq!(res.unwrap(), Some(RepoInfo::new(repo, false)));
} }
for repo in NON_EXISTENT_REPOS { for repo in NON_EXISTENT_REPOS {
let res = client.get_repo_info(&repo).await; let client = client.clone();
if matches!(res, Err(GhApiError::RateLimit { .. })) { tests.push((
continue; None,
} tokio::spawn(async move { client.get_repo_info(&repo).await }),
));
assert_eq!(res.unwrap(), None);
} }
if client.get_auth_token().is_some() { if client.get_auth_token().is_some() {
for repo in PRIVATE_REPOS { for repo in PRIVATE_REPOS {
let res = client.get_repo_info(&repo).await; let client = client.clone();
if matches!(res, Err(GhApiError::RateLimit { .. })) { tests.push((
continue; Some(RepoInfo::new(repo.clone(), true)),
} tokio::spawn(async move { client.get_repo_info(&repo).await }),
));
assert_eq!(res.unwrap(), Some(RepoInfo::new(repo, true)));
} }
} }
} }
for (expected, task) in tests {
assert_eq!(task.await.unwrap().unwrap(), expected);
}
} }
async fn test_specific_release(release: &GhRelease, artifacts: &[&str]) { async fn test_specific_release(release: &GhRelease, artifacts: &[&str]) {