Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe61c9af authored by Adrian Roos's avatar Adrian Roos
Browse files

VirtualDisplayTest: Rethrow runOnUiThread exceptions on test thread

Catches and rethrows exceptions on the test thread to
avoid taking down the entire instrumentation test when
tests fail.

Bug: 223843046
Test: atest VirtualDisplayTest
Change-Id: I78b6777ff3cabc532cd73390cc5b4c23f64ae127
parent 924b02bb
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -332,21 +332,23 @@ public class VirtualDisplayTest extends AndroidTestCase {
    }

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