From 26f0862b3037fccd3712e28ddf825d5e0dc1cbce Mon Sep 17 00:00:00 2001 From: Gigi Cheang Date: Thu, 11 Jun 2026 15:07:48 -0400 Subject: [PATCH] test: add retries + fix Signed-off-by: Gigi Cheang --- .../v2/CdTektonPipelineIT.java | 32 ++++++++++++-- .../cd_toolchain/v2/CdToolchainIT.java | 42 ++++++++++++++++++- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/modules/cd-tekton-pipeline/src/test/java/com/ibm/cloud/continuous_delivery/cd_tekton_pipeline/v2/CdTektonPipelineIT.java b/modules/cd-tekton-pipeline/src/test/java/com/ibm/cloud/continuous_delivery/cd_tekton_pipeline/v2/CdTektonPipelineIT.java index 5082d542..b8139e35 100644 --- a/modules/cd-tekton-pipeline/src/test/java/com/ibm/cloud/continuous_delivery/cd_tekton_pipeline/v2/CdTektonPipelineIT.java +++ b/modules/cd-tekton-pipeline/src/test/java/com/ibm/cloud/continuous_delivery/cd_tekton_pipeline/v2/CdTektonPipelineIT.java @@ -54,6 +54,7 @@ public class CdTektonPipelineIT extends SdkIntegrationTestBase { String triggerPropIdLink = null; String runIdLink = null; String rerunIdLink = null; + String runLogIdLink = null; String propertyName = "prop1"; String triggerName = "start-deploy"; String triggerPropName = "triggerProp1"; @@ -878,7 +879,6 @@ public void testListTektonPipelineRunsWithPager() throws Exception { } } -/* @Test(dependsOnMethods = { "testRerunTektonPipelineRun" }) public void testGetTektonPipelineRunLogs() throws Exception { try { @@ -895,6 +895,12 @@ public void testGetTektonPipelineRunLogs() throws Exception { LogsCollection logsCollectionResult = response.getResult(); assertNotNull(logsCollectionResult); + + // Store the first log ID for use in testGetTektonPipelineRunLogContent + if (logsCollectionResult.getLogs() != null && !logsCollectionResult.getLogs().isEmpty()) { + runLogIdLink = logsCollectionResult.getLogs().get(0).getId(); + assertNotNull(runLogIdLink); + } } catch (ServiceResponseException e) { fail(String.format("Service returned status code %d: %s%nError details: %s", e.getStatusCode(), e.getMessage(), e.getDebuggingInfo())); @@ -907,11 +913,30 @@ public void testGetTektonPipelineRunLogContent() throws Exception { GetTektonPipelineRunLogContentOptions getTektonPipelineRunLogContentOptions = new GetTektonPipelineRunLogContentOptions.Builder() .pipelineId(pipelineIdLink) .pipelineRunId(runIdLink) - .id() + .id(runLogIdLink) .build(); // Invoke operation - Response response = pipelineSvc.getTektonPipelineRunLogContent(getTektonPipelineRunLogContentOptions).execute(); + // Retry logic with exponential backoff to wait for log content to be available + Response response = null; + int maxRetries = 10; + long baseDelay = 1000L; + long maxDelay = 30000L; + + for (int i = 0; i < maxRetries; i++) { + try { + response = pipelineSvc.getTektonPipelineRunLogContent(getTektonPipelineRunLogContentOptions).execute(); + System.out.printf("Log content was retrieved successfully on attempt %d.%n", i + 1); + break; + } catch (Exception err) { + if (i == maxRetries - 1) { + throw err; + } + long retryDelay = Math.min(baseDelay * (1L << i), maxDelay); + System.out.printf("Attempt %d getting log content failed, retrying in %dms... Error: %s%n", i + 1, retryDelay, err.getMessage()); + Thread.sleep(retryDelay); + } + } // Validate response assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -923,7 +948,6 @@ public void testGetTektonPipelineRunLogContent() throws Exception { e.getStatusCode(), e.getMessage(), e.getDebuggingInfo())); } } -*/ @Test(dependsOnMethods = { "testCreateTektonPipeline", "testCreateTektonPipelineRun", "testGetTektonPipelineRun", "testListTektonPipelineRuns", "testListTektonPipelineRunsWithPager" }) diff --git a/modules/cd-toolchain/src/test/java/com/ibm/cloud/continuous_delivery/cd_toolchain/v2/CdToolchainIT.java b/modules/cd-toolchain/src/test/java/com/ibm/cloud/continuous_delivery/cd_toolchain/v2/CdToolchainIT.java index 5a99501e..5780b88d 100644 --- a/modules/cd-toolchain/src/test/java/com/ibm/cloud/continuous_delivery/cd_toolchain/v2/CdToolchainIT.java +++ b/modules/cd-toolchain/src/test/java/com/ibm/cloud/continuous_delivery/cd_toolchain/v2/CdToolchainIT.java @@ -326,7 +326,26 @@ public void testCreateToolchainEventApplicationJson() throws Exception { .build(); // Invoke operation - Response response = service.createToolchainEvent(createToolchainEventOptions).execute(); + // Retry logic with exponential backoff to wait for event creation to succeed + Response response = null; + int maxRetries = 10; + long baseDelay = 1000L; + long maxDelay = 30000L; + + for (int i = 0; i < maxRetries; i++) { + try { + response = service.createToolchainEvent(createToolchainEventOptions).execute(); + System.out.printf("Event was created successfully on attempt %d.%n", i + 1); + break; + } catch (Exception err) { + if (i == maxRetries - 1) { + throw err; + } + long retryDelay = Math.min(baseDelay * (1L << i), maxDelay); + System.out.printf("Attempt %d creating event failed, retrying in %dms... Error: %s%n", i + 1, retryDelay, err.getMessage()); + Thread.sleep(retryDelay); + } + } // Validate response assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -360,7 +379,26 @@ public void testCreateToolchainEventTextPlain() throws Exception { .build(); // Invoke operation - Response response = service.createToolchainEvent(createToolchainEventOptions).execute(); + // Retry logic with exponential backoff to wait for event creation to succeed + Response response = null; + int maxRetries = 10; + long baseDelay = 1000L; + long maxDelay = 30000L; + + for (int i = 0; i < maxRetries; i++) { + try { + response = service.createToolchainEvent(createToolchainEventOptions).execute(); + System.out.printf("Event was created successfully on attempt %d.%n", i + 1); + break; + } catch (Exception err) { + if (i == maxRetries - 1) { + throw err; + } + long retryDelay = Math.min(baseDelay * (1L << i), maxDelay); + System.out.printf("Attempt %d creating event failed, retrying in %dms... Error: %s%n", i + 1, retryDelay, err.getMessage()); + Thread.sleep(retryDelay); + } + } // Validate response assertNotNull(response); assertEquals(response.getStatusCode(), 200);