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

Rework 5s sleep with 100ms intervals #233

Merged
merged 1 commit into from
Jun 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/test/java/winstone/accesslog/SimpleAccessLoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ public void testSimpleConnection() throws Exception {
makeRequest("http://localhost:"+port+"/examples/CountRequestsServlet");

// check the log file
Thread.sleep(5000);
String text = FileUtils.readFileToString(logFile, StandardCharsets.UTF_8);
// check the log file every 100ms for 5s
String text = "";
for(int i=0; i < 50; ++i) {
Copy link
Member

@olamy olamy Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea of a loop should be to wait a certain time until reaching a conditon (it;s a fragile 5s timeout with such loop)
if you don't want to do it manually this can be easily achieved using http://www.awaitility.org/

Thread.sleep(100);
text = FileUtils.readFileToString(logFile, StandardCharsets.UTF_8);
if (!"".equals(text))
break;
}
assertEquals(String.format("127.0.0.1 - - GET /examples/CountRequestsServlet HTTP/1.1 200%n"),text);
}

Expand Down