Skip to content

Commit

Permalink
Fix test_has_release_artifact_and_download_artifacts
Browse files Browse the repository at this point in the history
Retry on rate limit

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Jun 10, 2024
1 parent 999ebb9 commit dfa2649
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions crates/binstalk-git-repo-api/src/gh_api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,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();
Expand All @@ -628,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 {
Expand All @@ -662,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
);
}));
Expand All @@ -679,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
);
}));
Expand Down

0 comments on commit dfa2649

Please sign in to comment.