Increase test coverage
Fixed an intermittent deadlock in MainTest: FlushListener could receive more than the expected number of flushes before the VirtualTerminalInteractor was given control. So by setting the flush count to zero in waitForFlushes(), flushes could be lost. Now it only reduces the number of flushes by the expected number.
This commit is contained in:
parent
a8620307c9
commit
2de2e3947a
|
@ -17,7 +17,7 @@ public class LispInterpreterFixture {
|
|||
private static LispInterpreter interpreter = null;
|
||||
|
||||
public static void buildInterpreter() {
|
||||
LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance();
|
||||
LispInterpreterBuilder builder = new LispInterpreterBuilderImpl() {};
|
||||
builder.setOutput(new PrintStream(outputStream));
|
||||
builder.setErrorOutput(new PrintStream(outputStream));
|
||||
builder.setNotInteractive();
|
||||
|
|
|
@ -41,9 +41,12 @@ public class MainTest {
|
|||
latch = new CountDownLatch(1);
|
||||
|
||||
new Thread(() -> {
|
||||
LispMain main = new LispMain(new LispInterpreterBuilderImpl() {}, terminal.getConfiguration());
|
||||
main.runInteractive();
|
||||
latch.countDown();
|
||||
try {
|
||||
LispMain main = new LispMain(new LispInterpreterBuilderImpl() {}, terminal.getConfiguration());
|
||||
main.runInteractive();
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
}).start();
|
||||
|
||||
return terminal;
|
||||
|
@ -121,8 +124,11 @@ public class MainTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void defaultConstructorCoverage() {
|
||||
new LispMain();
|
||||
public void runMain() {
|
||||
LispMain.main(new String[] { "test/main/test-files/file.lisp" });
|
||||
|
||||
assertEquals("", getSystemErrLog());
|
||||
assertEquals(format("{0}{1}{2}\n\n", ANSI_GREEN, "RADISH", ANSI_RESET), getSystemOutLog());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,12 +12,12 @@ public class FlushListener implements VirtualTerminalListener {
|
|||
this.flushCount = 0;
|
||||
}
|
||||
|
||||
public int getFlushCount() {
|
||||
public synchronized int getFlushCount() {
|
||||
return flushCount;
|
||||
}
|
||||
|
||||
public void resetFlushCount() {
|
||||
flushCount = 0;
|
||||
public synchronized void reduceFlushCount(int reduction) {
|
||||
flushCount -= reduction;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -110,7 +110,7 @@ public class VirtualTerminalInteractor {
|
|||
while (flushListener.getFlushCount() < flushCount)
|
||||
flushListener.wait();
|
||||
|
||||
flushListener.resetFlushCount();
|
||||
flushListener.reduceFlushCount(flushCount);
|
||||
}
|
||||
} catch (InterruptedException ignored) {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue