Protect against JS module call race condition while initializing react instance

Summary: Fixes a race condition where JS module functions could be called in between ##initializeWithInstance(catalystInstance);## and ##CatalystInstance#runJSBundle##, before the BatchedBridge in JS was set up. We now guarantee that all JS module methods that are called after `ReactContext#hasActiveCatalystInstance()` returns true will have the batched bridge created and ready to use.

Reviewed By: lexs

Differential Revision: D3258651

fb-gh-sync-id: 66e66533cc86d185e7c865376d6a5cdc6520d2d4
fbshipit-source-id: 66e66533cc86d185e7c865376d6a5cdc6520d2d4
This commit is contained in:
Andy Street
2016-05-05 05:51:45 -07:00
committed by Facebook Github Bot 0
parent a69b883537
commit a1ba0918ab
4 changed files with 72 additions and 40 deletions

View File

@@ -10,6 +10,8 @@ package com.facebook.react.testing;
import javax.annotation.Nullable;
import java.util.concurrent.Callable;
import android.app.Instrumentation;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
@@ -124,9 +126,21 @@ public class ReactTestHelper {
@Override
public CatalystInstance build() {
CatalystInstance instance = builder.build();
testCase.initializeWithInstance(instance);
instance.runJSBundle();
final CatalystInstance instance = builder.build();
try {
instance.getReactQueueConfiguration().getJSQueueThread().callOnQueue(
new Callable<Void>() {
@Override
public Void call() throws Exception {
testCase.initializeWithInstance(instance);
instance.runJSBundle();
return null;
}
}).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
testCase.waitForBridgeAndUIIdle();
return instance;
}