localstack/localstack-java-utils

Is isRunning method works fine?

wojciechszymski opened this issue · 4 comments

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).

This will be unit test for this fix:

localstack.start();
localstack.stop();
assertFalse(localstack.isRunning()); 

Could you upload following changes:

  1. In logic: cloud.localstack.Locastack:
    public void stop() {
        if (localStackContainer != null) {
            localStackContainer.stop();
            localStackContainer = null;
        }
        locked = false;
    }
  1. Unit test in cloud.localstack.dockerLocalstackDockerTest:
    @Test
    public void restart() {
        Localstack.INSTANCE.startup(DOCKER_CONFIG);
        Localstack.INSTANCE.stop();
        assertFalse(Localstack.INSTANCE.isRunning());
    }

@whummer

Thanks for reporting @wojciechszymski , and apologies for the long delay. This is potentially related to #82 . We believe that this should be fixed in the meantime - a new version 0.2.20 has been pushed to Maven Central. Can you please give it a try with that version? Please keep us posted if the problem persists.. Thanks!

Hi! We just wanted to follow up on our last message to see whether your issue has been resolved. Were you able to get it working with the latest version of LocalStack? We would appreciate your feedback!