Skip to content

Commit

Permalink
Ensure tests are running on the correct thread
Browse files Browse the repository at this point in the history
Summary: This diff re-enables commented code during the AndroidX migration

Reviewed By: PeteTheHeat

Differential Revision: D15758382

fbshipit-source-id: 95106cc2e3faccbd632d773ee58091c7bf8ea063
  • Loading branch information
mdvacca authored and facebook-github-bot committed Oct 8, 2019
1 parent b5ea49f commit 3b51499
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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;
}
Expand Down

0 comments on commit 3b51499

Please sign in to comment.