From a3058cc07c2194cc4b139a54e37954102860fead Mon Sep 17 00:00:00 2001 From: Lisa Chung Date: Fri, 3 May 2024 17:15:35 -0400 Subject: [PATCH] fix flaky integration tests in xample-domain (#2931) --- .github/workflows/xample-integration-test.yml | 5 ++-- .../xample/XampleJavaMicroserviceTest.java | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/workflows/xample-integration-test.yml b/.github/workflows/xample-integration-test.yml index 5b702ebd40..aef8c8f319 100644 --- a/.github/workflows/xample-integration-test.yml +++ b/.github/workflows/xample-integration-test.yml @@ -41,8 +41,6 @@ jobs: run: sleep 60s shell: bash - - - name: 'Check for RabbitMQ to be ready' uses: department-of-veterans-affairs/curl-action@v1.0.0 with: @@ -82,6 +80,7 @@ jobs: fi ./gradlew -p domain-xample integrationTest + - name: "Collect docker logs" if: always() uses: jwalton/gh-docker-logs@v2 @@ -102,7 +101,7 @@ jobs: echo "Unexpected ERROR logs in xample-workflows container" exit 11 fi - if docker logs vro_svc-xample-j_1 | grep 'ERROR\|WARN' | grep -v 'Simulated error'; then + if docker logs vro_svc-xample-j_1 | grep 'ERROR\|WARN' | grep -v 'Simulated error' | grep -v SimpleMessageListenerContainer ; then echo "Unexpected ERROR logs in svc-xample-j container" exit 12 fi diff --git a/domain-xample/svc-xample-j/src/integrationTest/java/gov/va/vro/services/xample/XampleJavaMicroserviceTest.java b/domain-xample/svc-xample-j/src/integrationTest/java/gov/va/vro/services/xample/XampleJavaMicroserviceTest.java index 36198db518..ac27cc7fef 100644 --- a/domain-xample/svc-xample-j/src/integrationTest/java/gov/va/vro/services/xample/XampleJavaMicroserviceTest.java +++ b/domain-xample/svc-xample-j/src/integrationTest/java/gov/va/vro/services/xample/XampleJavaMicroserviceTest.java @@ -1,14 +1,12 @@ package gov.va.vro.services.xample; import static gov.va.vro.services.xample.JavaMicroserviceApplication.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; import com.fasterxml.jackson.databind.ObjectMapper; import gov.va.vro.model.xample.SomeDtoModel; import gov.va.vro.model.xample.StatusValue; import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.Message; @@ -16,6 +14,10 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.retry.backoff.ExponentialBackOffPolicy; +import org.springframework.retry.backoff.ExponentialRandomBackOffPolicy; +import org.springframework.retry.policy.MaxAttemptsRetryPolicy; +import org.springframework.retry.support.RetryTemplate; import java.io.IOException; @@ -32,14 +34,22 @@ public class XampleJavaMicroserviceTest { @Autowired private RabbitAdmin rabbitAdmin; - @BeforeEach - private void setUp() { - rabbitAdmin.purgeQueue(queueName, true); + private final RetryTemplate retryTemplate = createRetryTemplate(); + + private static RetryTemplate createRetryTemplate() { + ExponentialBackOffPolicy backOffPolicy = new ExponentialRandomBackOffPolicy(); + backOffPolicy.setInitialInterval(2000); + + RetryTemplate retryTemplate = RetryTemplate.defaultInstance(); + retryTemplate.setBackOffPolicy(backOffPolicy); + retryTemplate.setRetryPolicy(new MaxAttemptsRetryPolicy(5)); + return retryTemplate; } - @AfterEach - private void tearDown() { - rabbitAdmin.purgeQueue(queueName, true); + @BeforeEach + private void setUp() { + rabbitTemplate.setRetryTemplate(retryTemplate); + rabbitAdmin.purgeQueue(queueName); } private final SomeDtoModel request =