Skip to content

Commit

Permalink
Add a unit test for #552
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jul 15, 2020
1 parent 0af26c0 commit f867197
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions terminal/src/test/java/org/jline/utils/NonBlockingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class NonBlockingTest {

Expand Down Expand Up @@ -57,6 +59,20 @@ public void testNonBlockingPumpReader() throws IOException {
writer.write('中');
assertEquals('中', nbr.read(100));
assertEquals(NonBlockingReader.READ_EXPIRED, nbr.read(100));

long t0 = System.currentTimeMillis();
new Thread(() -> {
try {
Thread.sleep(100);
writer.write('中');
} catch (Exception e) {
fail();
}
}).start();
int c = nbr.read(0);
long t1 = System.currentTimeMillis();
assertEquals('中', c);
assertTrue(t1 - t0 >= 100);
}

@Test
Expand Down

0 comments on commit f867197

Please sign in to comment.