Description
I try to make a simple e2e test (Java + Spring Framework) which check our API by stopping Localstack instance, sending message to broker instance and finally asserting HTTP error response code. This test is part of bigger test suite with DirtiesContext annotation (with after each method mode).
Out Localstack bean is customized. In Spring Configuration we defined a bean with custom init and destroy methods. Init method will be posted below, destroy method just send purge requests into all queues. We don't want to stop Localstack instance - time optimization.
Init method:
if (!localstack.isRunning()) {
localstack.startup(LOCALSTACK_CONFIGURATION);
Runtime.getRuntime().addShutdownHook(new Thread(localstack::stop));
}
After localstack.stop();
- our init method will never work because isRunning
method returns always true
even when docker doesn't have running containers (docker ps
return empty list).
If Localstack object (unfortunately a static object) has non-null instance of localStackContainer
- isRunning
method return true
response (with empty list of available ports underneath). Seems like stop
method do not unset localStackContainer
field?
Container.isRunning method:
try {
new PortCommand(containerId).execute();
return true;
} catch(Exception e) {
return false;
}
Could you allow to unset localStackContainer
field or just unset this instance inner stop
method? We just want to find out (using isRunning
method) that docker image is running or not to avoid unnecessary Localstack restart between single test (using DirtiesContext annotation).