Closed azapasnik closed 3 years ago
The issue is not with spying, but with having multiple different applications contexts that compete for messages. In case of your example - if you run SQSListenerIT
individually, all tests pass. If you run tests through Maven, they will randomly fail as you described. That's because DemoApplicationIT
runs first, creates application context with not-spied SQSListener
, then SQSListenerIT
test runs and creates another application context, this time with spied SQSListener
. Both of these listeners listen to the same queue, so test will fail randomly.
One way to overcome this issue is to create and use a set of new SQS queues with unique names for each new application context.
Hey everyone. I have a simple spring boot application with AWS SQS integration. In integration tests I tried to spy on method annotated with @SqsListener annotation and got a behavior where bean sometimes wasn't spied.
You can take a look at sample project here: https://github.com/Sanych/aws-sqs-spybean-troubleshooting
run
mvn clean verify
In this log one may notice, that 2 out of 3 test method were spied successfully: