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

testability - synchronous version of Express.listen() #20

Open
szczebel opened this issue Dec 10, 2020 · 0 comments
Open

testability - synchronous version of Express.listen() #20

szczebel opened this issue Dec 10, 2020 · 0 comments
Labels
question Further information is requested

Comments

@szczebel
Copy link

szczebel commented Dec 10, 2020

Express.listen() spawns a separate thread to instantiate and start underlying HttpServer.
This introduces a race condition if an automated test is trying to execute an http call to the express app right after call to listen().

Workaround:

public void start(int port) {
        System.out.println("Application starting...");
        CountDownLatch latch = new CountDownLatch(1);

        express = new Express();
        //configuration of routes omitted

        express.listen(latch::countDown, port);
        latch.await();
        System.out.println("Application started @ http:https://localhost:" + getPort()); 
}

I'd prefer not to have to use CountDownLatch.

@simonwep simonwep added the question Further information is requested label Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants