Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is isRunning method works fine? #81

Open
wojciechszymski opened this issue Nov 17, 2021 · 4 comments
Open

Is isRunning method works fine? #81

wojciechszymski opened this issue Nov 17, 2021 · 4 comments

Comments

@wojciechszymski
Copy link
Contributor

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

@wojciechszymski
Copy link
Contributor Author

This will be unit test for this fix:

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

@wojciechszymski
Copy link
Contributor Author

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

wojciechszymski pushed a commit to wojciechszymski/localstack-java-utils that referenced this issue Nov 29, 2021
@whummer
Copy link
Member

whummer commented Jan 22, 2022

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!

@lakkeger
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants