java-express
java-express copied to clipboard
testability - synchronous version of Express.listen()
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.