Skip to content

Commit

Permalink
Try reduce flackiness of VeniceTest
Browse files Browse the repository at this point in the history
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
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Mar 3, 2021
1 parent cbe7c44 commit be7f057
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -182,9 +183,14 @@ public LifecycleState getLifecycleState() {
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public FabricUIManager(
mEventDispatcher = eventDispatcher;
mShouldDeallocateEventDispatcher = false;
mEventBeatManager = eventBeatManager;
mReactApplicationContext.addLifecycleEventListener(this);
mReactApplicationContext.addLifecycleEventListenerAndCheckState(this);
}

public FabricUIManager(
Expand All @@ -189,7 +189,7 @@ public FabricUIManager(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public TimingModule(ReactApplicationContext reactContext, DevSupportManager devS

@Override
public void initialize() {
getReactApplicationContext().addLifecycleEventListener(this);
getReactApplicationContext().addLifecycleEventListenerAndCheckState(this);
HeadlessJsTaskContext headlessJsTaskContext =
HeadlessJsTaskContext.getInstance(getReactApplicationContext());
headlessJsTaskContext.addTaskEventListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DeviceInfoModule(ReactApplicationContext reactContext) {
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
mFontScale = reactContext.getResources().getConfiguration().fontScale;
mReactApplicationContext = reactContext;
mReactApplicationContext.addLifecycleEventListener(this);
mReactApplicationContext.addLifecycleEventListenerAndCheckState(this);
}

public DeviceInfoModule(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public ThemedReactContext(
}

@Override
public void addLifecycleEventListener(LifecycleEventListener listener) {
mReactApplicationContext.addLifecycleEventListener(listener);
public void addLifecycleEventListenerAndCheckState(LifecycleEventListener listener) {
mReactApplicationContext.addLifecycleEventListenerAndCheckState(listener);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public UIManagerModule(
mEventDispatcher,
minTimeLeftInFrameForNonBatchedOperationMs);

reactContext.addLifecycleEventListener(this);
reactContext.addLifecycleEventListenerAndCheckState(this);
}

@Deprecated
Expand All @@ -180,7 +180,7 @@ public UIManagerModule(
mEventDispatcher,
minTimeLeftInFrameForNonBatchedOperationMs);

reactContext.addLifecycleEventListener(this);
reactContext.addLifecycleEventListenerAndCheckState(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public int compare(Event lhs, Event rhs) {

public EventDispatcherImpl(ReactApplicationContext reactContext) {
mReactContext = reactContext;
mReactContext.addLifecycleEventListener(this);
mReactContext.addLifecycleEventListenerAndCheckState(this);
mReactEventEmitter = new ReactEventEmitter(mReactContext);
}

Expand Down

0 comments on commit be7f057

Please sign in to comment.