Skip to content

Commit

Permalink
fix flaky integration tests in xample-domain (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisac authored May 3, 2024
1 parent 9f2ac18 commit a3058cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/xample-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ jobs:
run: sleep 60s
shell: bash



- name: 'Check for RabbitMQ to be ready'
uses: department-of-veterans-affairs/[email protected]
with:
Expand Down Expand Up @@ -82,6 +80,7 @@ jobs:
fi
./gradlew -p domain-xample integrationTest
- name: "Collect docker logs"
if: always()
uses: jwalton/gh-docker-logs@v2
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
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;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
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;

Expand All @@ -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 =
Expand Down

0 comments on commit a3058cc

Please sign in to comment.