Skip to content

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

@szczebel

Description

@szczebel

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://localhost:" + getPort()); 
}

I'd prefer not to have to use CountDownLatch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions