Merge "VirtualDisplayTest: Rethrow runOnUiThread exceptions on test thread" into tm-dev

This commit is contained in:
Adrian Roos
2022-03-31 19:44:18 +00:00
committed by Android (Google) Code Review

View File

@@ -332,21 +332,23 @@ public class VirtualDisplayTest extends AndroidTestCase {
} }
private void runOnUiThread(Runnable runnable) { private void runOnUiThread(Runnable runnable) {
Runnable waiter = new Runnable() { final Throwable[] thrown = new Throwable[1];
@Override assertTrue("Timed out", mHandler.runWithScissors(() -> {
public void run() {
synchronized (this) {
notifyAll();
}
}
};
synchronized (waiter) {
mHandler.post(runnable);
mHandler.post(waiter);
try { try {
waiter.wait(TIMEOUT); runnable.run();
} catch (InterruptedException ex) { } catch (Throwable t) {
t.printStackTrace();
thrown[0] = t;
} }
}, TIMEOUT));
if (thrown[0] != null) {
if (thrown[0] instanceof RuntimeException) {
throw (RuntimeException) thrown[0];
}
if (thrown[0] instanceof Error) {
throw (Error) thrown[0];
}
throw new RuntimeException(thrown[0]);
} }
} }