Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/92830


Change subject: Make all AsyncTask based tests run on the UI Thread
......................................................................

Make all AsyncTask based tests run on the UI Thread

Apparently AsyncTask does not work reliably when called from
non UI threads. This makes sure that the execute method is
always called from the UI thread.

Change-Id: I8349789a24d1f394f4c8a063203c1aa4389cfbfd
---
M 
wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
1 file changed, 38 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/30/92830/1

diff --git 
a/wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
 
b/wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
index dd40b45..152bcb4 100644
--- 
a/wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
+++ 
b/wikipedia-it/src/main/java/org/wikimedia/wikipedia/test/concurrency/AsyncTaskTest.java
@@ -28,49 +28,59 @@
         startActivity(new Intent(), null, null);
     }
 
-    public void testFinishHandling() throws Exception {
+    public void testFinishHandling() throws Throwable {
         final CountDownLatch onFinishLatch = new CountDownLatch(1);
         final Integer returned = 42;
-        new ExceptionHandlingAsyncTask<Integer>(getDefaultExecutor()) {
+        runTestOnUiThread(new Runnable() {
             @Override
-            public void onFinish(Integer result) {
-                assertEquals(returned, result);
-                onFinishLatch.countDown();
-            }
+            public void run() {
+                new ExceptionHandlingAsyncTask<Integer>(getDefaultExecutor()) {
+                    @Override
+                    public void onFinish(Integer result) {
+                        assertEquals(returned, result);
+                        onFinishLatch.countDown();
+                    }
 
-            @Override
-            public void onCatch(Throwable caught) {
-                assertTrue("Exception called despite success", false);
-            }
+                    @Override
+                    public void onCatch(Throwable caught) {
+                        assertTrue("Exception called despite success", false);
+                    }
 
-            @Override
-            public Integer performTask() throws Throwable {
-                return returned;
+                    @Override
+                    public Integer performTask() throws Throwable {
+                        return returned;
+                    }
+                }.execute();
             }
-        }.execute();
+        });
         assertTrue(onFinishLatch.await(TASK_COMPLETION_TIMEOUT, 
TimeUnit.MILLISECONDS));
     }
 
-    public void testExceptionHandling() throws Exception {
+    public void testExceptionHandling() throws Throwable {
         final CountDownLatch exceptionLatch = new CountDownLatch(1);
         final Throwable thrown = new Exception();
-        new ExceptionHandlingAsyncTask<Void>(getDefaultExecutor()) {
+        runTestOnUiThread(new Runnable() {
             @Override
-            public void onFinish(Void result) {
-                assertTrue("onFinish called despite exception", false);
-            }
+            public void run() {
+                new ExceptionHandlingAsyncTask<Void>(getDefaultExecutor()) {
+                    @Override
+                    public void onFinish(Void result) {
+                        assertTrue("onFinish called despite exception", false);
+                    }
 
-            @Override
-            public void onCatch(Throwable caught) {
-                assertSame(caught, thrown);
-                exceptionLatch.countDown();
-            }
+                    @Override
+                    public void onCatch(Throwable caught) {
+                        assertSame(caught, thrown);
+                        exceptionLatch.countDown();
+                    }
 
-            @Override
-            public Void performTask() throws Throwable {
-                throw thrown;
+                    @Override
+                    public Void performTask() throws Throwable {
+                        throw thrown;
+                    }
+                }.execute();
             }
-        }.execute();
+        });
         assertTrue(exceptionLatch.await(TASK_COMPLETION_TIMEOUT, 
TimeUnit.MILLISECONDS));
     }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/92830
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8349789a24d1f394f4c8a063203c1aa4389cfbfd
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to