mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-25 06:40:03 +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
|
||||
);
|
||||
}));
|
||||
|
|
|
@ -218,7 +218,7 @@ mod test {
|
|||
|
||||
/// Mark this as an async fn so that you won't accidentally use it in
|
||||
/// sync context.
|
||||
async fn create_client() -> Client {
|
||||
fn create_client() -> Client {
|
||||
Client::new(
|
||||
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")),
|
||||
None,
|
||||
|
@ -231,31 +231,40 @@ mod test {
|
|||
|
||||
#[tokio::test]
|
||||
async fn test_crates_io_sparse_registry() {
|
||||
let client = create_client().await;
|
||||
|
||||
let sparse_registry: Registry = Registry::crates_io_sparse_registry();
|
||||
assert!(
|
||||
matches!(sparse_registry, Registry::Sparse(_)),
|
||||
"{:?}",
|
||||
sparse_registry
|
||||
);
|
||||
let client = create_client();
|
||||
|
||||
let crate_name = "cargo-binstall";
|
||||
let version_req = &VersionReq::parse("=1.0.0").unwrap();
|
||||
let manifest_from_sparse = sparse_registry
|
||||
.fetch_crate_matched(client.clone(), crate_name, version_req)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let serialized_manifest_from_sparse_task = tokio::spawn({
|
||||
let client = client.clone();
|
||||
let version_req = version_req.clone();
|
||||
|
||||
async move {
|
||||
let sparse_registry: Registry = Registry::crates_io_sparse_registry();
|
||||
assert!(
|
||||
matches!(sparse_registry, Registry::Sparse(_)),
|
||||
"{:?}",
|
||||
sparse_registry
|
||||
);
|
||||
|
||||
let manifest_from_sparse = sparse_registry
|
||||
.fetch_crate_matched(client, crate_name, &version_req)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
to_string(&manifest_from_sparse).unwrap()
|
||||
}
|
||||
});
|
||||
|
||||
let manifest_from_cratesio_api = fetch_crate_cratesio_api(client, crate_name, version_req)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let serialized_manifest_from_sparse = to_string(&manifest_from_sparse).unwrap();
|
||||
let serialized_manifest_from_cratesio_api = to_string(&manifest_from_cratesio_api).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
serialized_manifest_from_sparse,
|
||||
serialized_manifest_from_sparse_task.await.unwrap(),
|
||||
serialized_manifest_from_cratesio_api
|
||||
);
|
||||
}
|
||||
|
@ -263,34 +272,42 @@ mod test {
|
|||
#[cfg(feature = "git")]
|
||||
#[tokio::test]
|
||||
async fn test_crates_io_git_registry() {
|
||||
let client = create_client().await;
|
||||
|
||||
let git_registry: Registry = "https://github.com/rust-lang/crates.io-index"
|
||||
.parse()
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(git_registry, Registry::Git(_)),
|
||||
"{:?}",
|
||||
git_registry
|
||||
);
|
||||
let client = create_client();
|
||||
|
||||
let crate_name = "cargo-binstall";
|
||||
let version_req = &VersionReq::parse("=1.0.0").unwrap();
|
||||
let manifest_from_git = git_registry
|
||||
.fetch_crate_matched(client.clone(), crate_name, version_req)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let serialized_manifest_from_git_task = tokio::spawn({
|
||||
let version_req = version_req.clone();
|
||||
let client = client.clone();
|
||||
|
||||
async move {
|
||||
let git_registry: Registry = "https://github.com/rust-lang/crates.io-index"
|
||||
.parse()
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(git_registry, Registry::Git(_)),
|
||||
"{:?}",
|
||||
git_registry
|
||||
);
|
||||
|
||||
let manifest_from_git = git_registry
|
||||
.fetch_crate_matched(client, crate_name, &version_req)
|
||||
.await
|
||||
.unwrap();
|
||||
to_string(&manifest_from_git).unwrap()
|
||||
}
|
||||
});
|
||||
|
||||
let manifest_from_cratesio_api = Registry::default()
|
||||
.fetch_crate_matched(client, crate_name, version_req)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let serialized_manifest_from_git = to_string(&manifest_from_git).unwrap();
|
||||
let serialized_manifest_from_cratesio_api = to_string(&manifest_from_cratesio_api).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
serialized_manifest_from_git,
|
||||
serialized_manifest_from_git_task.await.unwrap(),
|
||||
serialized_manifest_from_cratesio_api
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue