Skip to content

Commit

Permalink
concord-server-it: retry attachment download
Browse files Browse the repository at this point in the history
  • Loading branch information
ibodrov committed Jan 17, 2025
1 parent ad8bbf8 commit 1337d58
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.*;

import static com.walmartlabs.concord.it.common.ServerClient.*;
import static java.util.Collections.singletonMap;
Expand Down Expand Up @@ -124,12 +121,11 @@ public void testFailure() throws Exception {

// ---

ProcessApi processApi = new ProcessApi(getApiClient());
waitForStatus(getApiClient(), spr.getInstanceId(), ProcessEntry.StatusEnum.FAILED);

// ---

try (InputStream resp = processApi.downloadAttachment(spr.getInstanceId(), "ansible_stats.json")) {
try (InputStream resp = downloadAttachment(spr.getInstanceId(), "ansible_stats.json")) {
assertNotNull(resp);

Map<String, Object> stats = fromJson(resp);
Expand Down Expand Up @@ -180,7 +176,6 @@ public void test(Map<String, Object> input) throws Exception {

// ---

ProcessApi processApi = new ProcessApi(getApiClient());
ProcessEntry psr = waitForCompletion(getApiClient(), spr.getInstanceId());

// ---
Expand All @@ -193,7 +188,7 @@ public void test(Map<String, Object> input) throws Exception {

// ---

try (InputStream resp = processApi.downloadAttachment(spr.getInstanceId(), "ansible_stats.json")) {
try (InputStream resp = downloadAttachment(spr.getInstanceId(), "ansible_stats.json")) {
assertNotNull(resp);
Map<String, Object> stats = fromJson(resp);

Expand All @@ -207,4 +202,19 @@ public void test(Map<String, Object> input) throws Exception {
private static InputStream resource(String path) {
return AnsibleProjectIT.class.getResourceAsStream(path);
}

private InputStream downloadAttachment(UUID instanceId, String name) throws InterruptedException, ApiException {
int attemptsLeft = 3;
while (true) {
try {
return new ProcessApi(getApiClient()).downloadAttachment(instanceId, name);
} catch (ApiException e) {
if (attemptsLeft-- > 0 && (e.getCode() == 404 || e.getCode() >= 500)) {
Thread.sleep(500);
} else {
throw e;
}
}
}
}
}

0 comments on commit 1337d58

Please sign in to comment.