Fix ReactInstanceManager deadlock

Summary:
D12829677 introduced a deadlock where onHostResume holds the lock on `moveToResumedLifecycleState()` then waits for the `mReactContext` lock, but at the same time setupReactContext holds the `mReactContext` lock and waits for `moveToResumedLifecycleState()` https://our.intern.facebook.com/intern/everpaste/?handle=GAgXFgLQH1ZlQikBAMQzo2LZ6h9TbiAxAAAz. The purpose of the previous diff was to make sure that detachRootoView and
setupReactContext did not interfere with each other, and implemented that by blocking on mReactContext. Since this overloads the usage of mReactContext, let's use a different lock `mAttachedRootViews` to implement this behavior instead

Reviewed By: mdvacca

Differential Revision: D12989555

fbshipit-source-id: c12e5fd9c5fa4c2037167e9400dc0c1578e38959
This commit is contained in:
Andrew Chen (Eng)
2018-11-09 13:41:17 -08:00
committed by Facebook Github Bot
parent 80f92adf1f
commit df7e8c64ff
2 changed files with 41 additions and 16 deletions

View File

@@ -22,6 +22,8 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ReactInstanceManagerTest {
private static final String TEST_MODULE = "ViewLayoutTestApp";
private ReactInstanceManager mReactInstanceManager;
private ReactRootView mReactRootView;
@@ -45,7 +47,25 @@ public class ReactInstanceManagerTest {
@UiThreadTest
public void testMountUnmount() {
mReactInstanceManager.onHostResume(mActivityRule.getActivity());
mReactRootView.startReactApplication(mReactInstanceManager, "ViewLayoutTestApp");
mReactRootView.startReactApplication(mReactInstanceManager, TEST_MODULE);
mReactRootView.unmountReactApplication();
}
@Test
@UiThreadTest
public void testResume() throws InterruptedException {
mReactInstanceManager.onHostResume(mActivityRule.getActivity());
mReactRootView.startReactApplication(mReactInstanceManager, TEST_MODULE);
Thread.sleep(1000);
mReactInstanceManager.onHostResume(mActivityRule.getActivity());
}
@Test
@UiThreadTest
public void testRecreateContext() throws InterruptedException {
mReactInstanceManager.onHostResume(mActivityRule.getActivity());
mReactInstanceManager.createReactContextInBackground();
Thread.sleep(1000);
mReactRootView.startReactApplication(mReactInstanceManager, TEST_MODULE);
}
}