Try reduce flackiness of VeniceTest

Summary:
Simplify addLifecycleEventListener for the flaky test because we just want to test that listener is working.

Changelog:
[Android][Changed] - Add a spare implementation of addLifecycleEventListener for test purpose.

Reviewed By: PeteTheHeat

Differential Revision: D26749256

fbshipit-source-id: 5af216e6bfa37a15eb189aa24a3df35a7a7112de
This commit is contained in:
Lulu Wu
2021-03-02 16:32:44 -08:00
committed by Facebook GitHub Bot
parent cbe7c445f7
commit be7f057bac
7 changed files with 16 additions and 10 deletions
@@ -23,6 +23,7 @@ import com.facebook.react.bridge.queue.MessageQueueThread;
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.config.ReactFeatureFlags;
import java.lang.ref.WeakReference;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -182,9 +183,14 @@ public class ReactContext extends ContextWrapper {
return mLifecycleState;
}
@VisibleForTesting
public void addLifecycleEventListener(final LifecycleEventListener listener) {
mLifecycleEventListeners.add(listener);
if (hasActiveCatalystInstance() || isBridgeless()) {
}
public void addLifecycleEventListenerAndCheckState(final LifecycleEventListener listener) {
mLifecycleEventListeners.add(listener);
if (hasActiveCatalystInstance()) {
switch (mLifecycleState) {
case BEFORE_CREATE:
case BEFORE_RESUME:
@@ -176,7 +176,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
mEventDispatcher = eventDispatcher;
mShouldDeallocateEventDispatcher = false;
mEventBeatManager = eventBeatManager;
mReactApplicationContext.addLifecycleEventListener(this);
mReactApplicationContext.addLifecycleEventListenerAndCheckState(this);
}
public FabricUIManager(
@@ -189,7 +189,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
mEventDispatcher = new EventDispatcherImpl(reactContext);
mShouldDeallocateEventDispatcher = true;
mEventBeatManager = eventBeatManager;
mReactApplicationContext.addLifecycleEventListener(this);
mReactApplicationContext.addLifecycleEventListenerAndCheckState(this);
}
// TODO (T47819352): Rename this to startSurface for consistency with xplat/iOS
@@ -68,7 +68,7 @@ public final class TimingModule extends NativeTimingSpec
@Override
public void initialize() {
getReactApplicationContext().addLifecycleEventListener(this);
getReactApplicationContext().addLifecycleEventListenerAndCheckState(this);
HeadlessJsTaskContext headlessJsTaskContext =
HeadlessJsTaskContext.getInstance(getReactApplicationContext());
headlessJsTaskContext.addTaskEventListener(this);
@@ -37,7 +37,7 @@ public class DeviceInfoModule extends NativeDeviceInfoSpec implements LifecycleE
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mFontScale = reactContext.getResources().getConfiguration().fontScale;
mReactApplicationContext = reactContext;
mReactApplicationContext.addLifecycleEventListener(this);
mReactApplicationContext.addLifecycleEventListenerAndCheckState(this);
}
public DeviceInfoModule(Context context) {
@@ -56,8 +56,8 @@ public class ThemedReactContext extends ReactContext {
}
@Override
public void addLifecycleEventListener(LifecycleEventListener listener) {
mReactApplicationContext.addLifecycleEventListener(listener);
public void addLifecycleEventListenerAndCheckState(LifecycleEventListener listener) {
mReactApplicationContext.addLifecycleEventListenerAndCheckState(listener);
}
@Override
@@ -158,7 +158,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule
mEventDispatcher,
minTimeLeftInFrameForNonBatchedOperationMs);
reactContext.addLifecycleEventListener(this);
reactContext.addLifecycleEventListenerAndCheckState(this);
}
@Deprecated
@@ -180,7 +180,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule
mEventDispatcher,
minTimeLeftInFrameForNonBatchedOperationMs);
reactContext.addLifecycleEventListener(this);
reactContext.addLifecycleEventListenerAndCheckState(this);
}
/**
@@ -104,7 +104,7 @@ public class EventDispatcherImpl implements EventDispatcher, LifecycleEventListe
public EventDispatcherImpl(ReactApplicationContext reactContext) {
mReactContext = reactContext;
mReactContext.addLifecycleEventListener(this);
mReactContext.addLifecycleEventListenerAndCheckState(this);
mReactEventEmitter = new ReactEventEmitter(mReactContext);
}