Skip to content

Commit 0a92105

Browse files
authored
test: add retries + fix (#125)
Signed-off-by: Gigi Cheang <gigi.cheang@ibm.com>
1 parent 5100540 commit 0a92105

2 files changed

Lines changed: 68 additions & 6 deletions

File tree

  • modules
    • cd-tekton-pipeline/src/test/java/com/ibm/cloud/continuous_delivery/cd_tekton_pipeline/v2
    • cd-toolchain/src/test/java/com/ibm/cloud/continuous_delivery/cd_toolchain/v2

modules/cd-tekton-pipeline/src/test/java/com/ibm/cloud/continuous_delivery/cd_tekton_pipeline/v2/CdTektonPipelineIT.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class CdTektonPipelineIT extends SdkIntegrationTestBase {
5454
String triggerPropIdLink = null;
5555
String runIdLink = null;
5656
String rerunIdLink = null;
57+
String runLogIdLink = null;
5758
String propertyName = "prop1";
5859
String triggerName = "start-deploy";
5960
String triggerPropName = "triggerProp1";
@@ -878,7 +879,6 @@ public void testListTektonPipelineRunsWithPager() throws Exception {
878879
}
879880
}
880881

881-
/*
882882
@Test(dependsOnMethods = { "testRerunTektonPipelineRun" })
883883
public void testGetTektonPipelineRunLogs() throws Exception {
884884
try {
@@ -895,6 +895,12 @@ public void testGetTektonPipelineRunLogs() throws Exception {
895895

896896
LogsCollection logsCollectionResult = response.getResult();
897897
assertNotNull(logsCollectionResult);
898+
899+
// Store the first log ID for use in testGetTektonPipelineRunLogContent
900+
if (logsCollectionResult.getLogs() != null && !logsCollectionResult.getLogs().isEmpty()) {
901+
runLogIdLink = logsCollectionResult.getLogs().get(0).getId();
902+
assertNotNull(runLogIdLink);
903+
}
898904
} catch (ServiceResponseException e) {
899905
fail(String.format("Service returned status code %d: %s%nError details: %s",
900906
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()));
@@ -907,11 +913,30 @@ public void testGetTektonPipelineRunLogContent() throws Exception {
907913
GetTektonPipelineRunLogContentOptions getTektonPipelineRunLogContentOptions = new GetTektonPipelineRunLogContentOptions.Builder()
908914
.pipelineId(pipelineIdLink)
909915
.pipelineRunId(runIdLink)
910-
.id()
916+
.id(runLogIdLink)
911917
.build();
912918

913919
// Invoke operation
914-
Response<StepLog> response = pipelineSvc.getTektonPipelineRunLogContent(getTektonPipelineRunLogContentOptions).execute();
920+
// Retry logic with exponential backoff to wait for log content to be available
921+
Response<StepLog> response = null;
922+
int maxRetries = 10;
923+
long baseDelay = 1000L;
924+
long maxDelay = 30000L;
925+
926+
for (int i = 0; i < maxRetries; i++) {
927+
try {
928+
response = pipelineSvc.getTektonPipelineRunLogContent(getTektonPipelineRunLogContentOptions).execute();
929+
System.out.printf("Log content was retrieved successfully on attempt %d.%n", i + 1);
930+
break;
931+
} catch (Exception err) {
932+
if (i == maxRetries - 1) {
933+
throw err;
934+
}
935+
long retryDelay = Math.min(baseDelay * (1L << i), maxDelay);
936+
System.out.printf("Attempt %d getting log content failed, retrying in %dms... Error: %s%n", i + 1, retryDelay, err.getMessage());
937+
Thread.sleep(retryDelay);
938+
}
939+
}
915940
// Validate response
916941
assertNotNull(response);
917942
assertEquals(response.getStatusCode(), 200);
@@ -923,7 +948,6 @@ public void testGetTektonPipelineRunLogContent() throws Exception {
923948
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()));
924949
}
925950
}
926-
*/
927951

928952

929953
@Test(dependsOnMethods = { "testCreateTektonPipeline", "testCreateTektonPipelineRun", "testGetTektonPipelineRun", "testListTektonPipelineRuns", "testListTektonPipelineRunsWithPager" })

modules/cd-toolchain/src/test/java/com/ibm/cloud/continuous_delivery/cd_toolchain/v2/CdToolchainIT.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,26 @@ public void testCreateToolchainEventApplicationJson() throws Exception {
326326
.build();
327327

328328
// Invoke operation
329-
Response<ToolchainEventPost> response = service.createToolchainEvent(createToolchainEventOptions).execute();
329+
// Retry logic with exponential backoff to wait for event creation to succeed
330+
Response<ToolchainEventPost> response = null;
331+
int maxRetries = 10;
332+
long baseDelay = 1000L;
333+
long maxDelay = 30000L;
334+
335+
for (int i = 0; i < maxRetries; i++) {
336+
try {
337+
response = service.createToolchainEvent(createToolchainEventOptions).execute();
338+
System.out.printf("Event was created successfully on attempt %d.%n", i + 1);
339+
break;
340+
} catch (Exception err) {
341+
if (i == maxRetries - 1) {
342+
throw err;
343+
}
344+
long retryDelay = Math.min(baseDelay * (1L << i), maxDelay);
345+
System.out.printf("Attempt %d creating event failed, retrying in %dms... Error: %s%n", i + 1, retryDelay, err.getMessage());
346+
Thread.sleep(retryDelay);
347+
}
348+
}
330349
// Validate response
331350
assertNotNull(response);
332351
assertEquals(response.getStatusCode(), 200);
@@ -360,7 +379,26 @@ public void testCreateToolchainEventTextPlain() throws Exception {
360379
.build();
361380

362381
// Invoke operation
363-
Response<ToolchainEventPost> response = service.createToolchainEvent(createToolchainEventOptions).execute();
382+
// Retry logic with exponential backoff to wait for event creation to succeed
383+
Response<ToolchainEventPost> response = null;
384+
int maxRetries = 10;
385+
long baseDelay = 1000L;
386+
long maxDelay = 30000L;
387+
388+
for (int i = 0; i < maxRetries; i++) {
389+
try {
390+
response = service.createToolchainEvent(createToolchainEventOptions).execute();
391+
System.out.printf("Event was created successfully on attempt %d.%n", i + 1);
392+
break;
393+
} catch (Exception err) {
394+
if (i == maxRetries - 1) {
395+
throw err;
396+
}
397+
long retryDelay = Math.min(baseDelay * (1L << i), maxDelay);
398+
System.out.printf("Attempt %d creating event failed, retrying in %dms... Error: %s%n", i + 1, retryDelay, err.getMessage());
399+
Thread.sleep(retryDelay);
400+
}
401+
}
364402
// Validate response
365403
assertNotNull(response);
366404
assertEquals(response.getStatusCode(), 200);

0 commit comments

Comments
 (0)