Add test to check async virtual call resolution. Fix bug in async unit

tests support
This commit is contained in:
Alexey Andreev 2015-02-06 19:02:14 +04:00
parent 1f8ef1092c
commit ce2c625f53
3 changed files with 33 additions and 3 deletions

View File

@ -16,6 +16,8 @@
package org.teavm.classlib.java.lang;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
/**
@ -28,7 +30,7 @@ public class ThreadTest {
long start = System.currentTimeMillis();
Thread.sleep(100);
long duration = System.currentTimeMillis() - start;
assertTrue("Thread.sleed did not wait enogh", duration < 100);
assertTrue("Thread.sleed did not wait enogh", duration >= 100);
}
@Test
@ -41,8 +43,34 @@ public class ThreadTest {
}
}
private void throwException() {
Thread.yield();
throw new IllegalStateException();
}
@Test
public void asyncVirtualCallsSupported() {
List<A> alist = new ArrayList<>();
alist.add(new A() {
@Override int foo() {
return 3;
}
});
alist.add(new A() {
@Override int foo() {
Thread.yield();
return 5;
}
});
int sum = 0;
for (A a : alist) {
sum += a.foo();
}
assertEquals(8, sum);
}
abstract class A {
abstract int foo();
}
}

View File

@ -923,7 +923,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
writer.append(" $return($rt_asyncResult(");
}
if (statement.getResult() != null) {
writer.append(' ');
if (!async) {
writer.append(' ');
}
prevCallSite = debugEmitter.emitCallSite();
statement.getResult().acceptVisitor(this);
debugEmitter.emitCallSite();

View File

@ -537,7 +537,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
private List<ClassNode> modelToAst(ListableClassHolderSource classes) {
AsyncMethodFinder asyncFinder = new AsyncMethodFinder(dependencyChecker.getCallGraph(), diagnostics);
asyncFinder.find(classes);
asyncMethods.addAll(asyncMethods);
asyncMethods.addAll(asyncFinder.getAsyncMethods());
progressListener.phaseStarted(TeaVMPhase.DECOMPILATION, classes.getClassNames().size());
Decompiler decompiler = new Decompiler(classes, classLoader, asyncFinder.getAsyncMethods());