From 95f07d80a72a28f57b9a1617353be47014f617be Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Thu, 23 Feb 2017 16:03:14 +0000 Subject: [PATCH] Add a test for an issue which I believe is caused by failure to identify an asynchronous method. Unfortunately I am unable to actually produce a failing test; instead an exception message is generated during test execution. This seems to be an issue with the test runner mechanism. --- tests/src/test/java/org/teavm/vm/VMTest.java | 28 +++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/src/test/java/org/teavm/vm/VMTest.java b/tests/src/test/java/org/teavm/vm/VMTest.java index 2d11709f8..ca8d233ca 100644 --- a/tests/src/test/java/org/teavm/vm/VMTest.java +++ b/tests/src/test/java/org/teavm/vm/VMTest.java @@ -167,6 +167,13 @@ public class VMTest { assertEquals("ok", acl.instanceState); } + @Test + public void asyncWait() { + AsyncClinitClass acl = new AsyncClinitClass(); + acl.doWait(); + assertEquals("ok", acl.instanceState); + } + @Test @SkipJVM public void loopAndExceptionPhi() { @@ -244,13 +251,28 @@ public class VMTest { public static String bar() { return "bar"; } - + public AsyncClinitClass() { instanceState += "ok"; try { Thread.sleep(1); + } catch (InterruptedException ie) { + throw new RuntimeException(ie); } - catch (InterruptedException ie) { + } + + public synchronized void doWait() { + new Thread(() -> { + synchronized (AsyncClinitClass.this) { + notify(); + } + }).start(); + + try { + Thread.sleep(1); + wait(); + } catch (InterruptedException ie) { + instanceState = "error"; throw new RuntimeException(ie); } } @@ -294,4 +316,4 @@ public class VMTest { super(ONE); } } -} +} \ No newline at end of file