Skip to content

Commit

Permalink
Safe testing of flushing in writing thread
Browse files Browse the repository at this point in the history
  • Loading branch information
pmwmedia committed Jan 18, 2016
1 parent a3e93c3 commit c36bf77
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions tests/src/org/pmw/tinylog/WritingThreadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,17 @@ public final void testFlush() throws InterruptedException {
DummyWriter writer2 = new DummyWriter();

WritingThread writingThread = new WritingThread(null, Thread.NORM_PRIORITY);
writingThread.start();

writingThread.putLogEntry(writer1, new LogEntryBuilder().message("one").create());
writingThread.putLogEntry(writer2, new LogEntryBuilder().message("two").create());
writingThread.putLogEntry(writer1, new LogEntryBuilder().message("three").create());
writingThread.putLogEntry(writer1, new LogEntryBuilder().message("four").create());
writingThread.putLogEntry(writer1, new LogEntryBuilder().message("five").create());

writingThread.start();
writingThread.shutdown();
writingThread.join();

assertTrue(writer1.numberOfFlushes >= 1); // Should be flushed at least once
assertTrue(writer1.numberOfFlushes < 4); // ... and ideally less than four times

assertEquals(1, writer2.numberOfFlushes); // Should be flushed exactly once
assertEquals(1, writer1.numberOfFlushes);
assertEquals(1, writer2.numberOfFlushes);
}

/**
Expand Down

0 comments on commit c36bf77

Please sign in to comment.