From 3b51499fc232cd824d15bb72144cfc1d6b4fb5ad Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 7 Oct 2019 18:54:26 -0700 Subject: [PATCH] Ensure tests are running on the correct thread Summary: This diff re-enables commented code during the AndroidX migration Reviewed By: PeteTheHeat Differential Revision: D15758382 fbshipit-source-id: 95106cc2e3faccbd632d773ee58091c7bf8ea063 --- .../testing/ReactIntegrationTestCase.java | 5 ++- .../react/testing/ReactTestHelper.java | 31 ++++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java index 09aac4a0e302d3..8a826d16ee4451 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java @@ -12,6 +12,7 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.Nullable; +import androidx.test.InstrumentationRegistry; import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.BaseJavaModule; import com.facebook.react.bridge.CatalystInstance; @@ -163,9 +164,7 @@ public boolean waitForBridgeIdle(long millis) { } public void waitForIdleSync() { - return; - // TODO: re-enable after cleanup of android-x migration - // InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); } public void waitForBridgeAndUIIdle() { diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java index 16d186421ea7b1..870318a64dd916 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java @@ -6,10 +6,12 @@ */ package com.facebook.react.testing; +import android.app.Instrumentation; import android.content.Context; import android.view.View; import android.view.ViewGroup; import androidx.annotation.Nullable; +import androidx.test.InstrumentationRegistry; import com.android.internal.util.Predicate; import com.facebook.infer.annotation.Assertions; import com.facebook.react.NativeModuleRegistryBuilder; @@ -110,13 +112,11 @@ public ReactInstanceManagerBuilder getReactInstanceManagerBuilder() { } public static ReactTestFactory getReactTestFactory() { - // TODO: re-enable after cleanup of android-x migration - // Instrumentation inst = InstrumentationRegistry.getInstrumentation(); - // if (!(inst instanceof ReactTestFactory)) { - return new DefaultReactTestFactory(); - // } - // - // return (ReactTestFactory) inst; + Instrumentation inst = InstrumentationRegistry.getInstrumentation(); + if (!(inst instanceof ReactTestFactory)) { + return new DefaultReactTestFactory(); + } + return (ReactTestFactory) inst; } public static ReactTestFactory.ReactInstanceEasyBuilder catalystInstanceBuilder( @@ -142,14 +142,15 @@ public CatalystInstance build() { final CatalystInstance instance = builder.build(); testCase.initializeWithInstance(instance); instance.runJSBundle(); - // TODO: re-enable after cleanup of android-x migration - // InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() { - // @Override - // public void run() { - ReactChoreographer.initialize(); - instance.initialize(); - // } - // }); + InstrumentationRegistry.getInstrumentation() + .runOnMainSync( + new Runnable() { + @Override + public void run() { + ReactChoreographer.initialize(); + instance.initialize(); + } + }); testCase.waitForBridgeAndUIIdle(); return instance; }