mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 14:28:42 +00:00
Speedup ci (#1724)
* Optimize binstalk-git-repo-api Use a dedicated github token in CI Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Speedup CI using `cargo-nextest` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix release profile override on Windows Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Optimize unit test in binstalk-registry Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Use `secrets.CI_RELEASE_TEST_GITHUB_TOKEN` for just-setup Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix unit testing in justfile Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add retry on rate limit in unit testing Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Only use `CI_UNIT_TEST_GITHUB_TOKEN` in unit testing Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `test_get_repo_info`: Retry on rate limit Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `test_has_release_artifact_and_download_artifacts` Retry on rate limit Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
52f172c713
commit
3aae883467
5 changed files with 356 additions and 308 deletions
|
@ -508,7 +508,7 @@ mod test {
|
|||
|
||||
let mut gh_clients = vec![GhApiClient::new(client.clone(), None)];
|
||||
|
||||
if let Ok(token) = env::var("GITHUB_TOKEN") {
|
||||
if let Ok(token) = env::var("CI_UNIT_TEST_GITHUB_TOKEN") {
|
||||
gh_clients.push(GhApiClient::new(client, Some(token.into())));
|
||||
}
|
||||
|
||||
|
@ -535,40 +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 { client.get_repo_info(&repo).await }),
|
||||
));
|
||||
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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -606,6 +602,20 @@ mod test {
|
|||
let mut tasks = Vec::new();
|
||||
|
||||
for client in create_client() {
|
||||
async fn has_release_artifact(
|
||||
client: &GhApiClient,
|
||||
artifact: &GhReleaseArtifact,
|
||||
) -> Result<Option<GhReleaseArtifactUrl>, GhApiError> {
|
||||
loop {
|
||||
match client.has_release_artifact(artifact.clone()).await {
|
||||
Err(GhApiError::RateLimit { retry_after }) => {
|
||||
sleep(retry_after.unwrap_or(DEFAULT_RETRY_AFTER)).await
|
||||
}
|
||||
res => break res,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (release, artifacts) in RELEASES {
|
||||
for artifact_name in artifacts {
|
||||
let client = client.clone();
|
||||
|
@ -632,15 +642,10 @@ mod test {
|
|||
.into_bytes(),
|
||||
)
|
||||
});
|
||||
|
||||
let artifact_url = loop {
|
||||
match client.has_release_artifact(artifact.clone()).await {
|
||||
Err(GhApiError::RateLimit { retry_after }) => {
|
||||
sleep(retry_after.unwrap_or(DEFAULT_RETRY_AFTER)).await
|
||||
}
|
||||
res => break res.unwrap().unwrap(),
|
||||
}
|
||||
};
|
||||
let artifact_url = has_release_artifact(&client, &artifact)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
if let Some(browser_download_task) = browser_download_task {
|
||||
let artifact_download_data = loop {
|
||||
|
@ -666,13 +671,15 @@ mod test {
|
|||
let client = client.clone();
|
||||
tasks.push(tokio::spawn(async move {
|
||||
assert_eq!(
|
||||
client
|
||||
.has_release_artifact(GhReleaseArtifact {
|
||||
has_release_artifact(
|
||||
&client,
|
||||
&GhReleaseArtifact {
|
||||
release,
|
||||
artifact_name: "123z".to_compact_string(),
|
||||
})
|
||||
.await
|
||||
.unwrap(),
|
||||
}
|
||||
)
|
||||
.await
|
||||
.unwrap(),
|
||||
None
|
||||
);
|
||||
}));
|
||||
|
@ -683,13 +690,15 @@ mod test {
|
|||
|
||||
tasks.push(tokio::spawn(async move {
|
||||
assert_eq!(
|
||||
client
|
||||
.has_release_artifact(GhReleaseArtifact {
|
||||
has_release_artifact(
|
||||
&client,
|
||||
&GhReleaseArtifact {
|
||||
release,
|
||||
artifact_name: "1234".to_compact_string(),
|
||||
})
|
||||
.await
|
||||
.unwrap(),
|
||||
}
|
||||
)
|
||||
.await
|
||||
.unwrap(),
|
||||
None
|
||||
);
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue