Skip to content

Commit be7f057

Browse files
luluwu2032facebook-github-bot
authored andcommittedMar 3, 2021
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
1 parent cbe7c44 commit be7f057

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
2424
import com.facebook.react.common.LifecycleState;
2525
import com.facebook.react.common.ReactConstants;
26+
import com.facebook.react.common.annotations.VisibleForTesting;
2627
import com.facebook.react.config.ReactFeatureFlags;
2728
import java.lang.ref.WeakReference;
2829
import java.util.concurrent.CopyOnWriteArraySet;
@@ -182,9 +183,14 @@ public LifecycleState getLifecycleState() {
182183
return mLifecycleState;
183184
}
184185

186+
@VisibleForTesting
185187
public void addLifecycleEventListener(final LifecycleEventListener listener) {
186188
mLifecycleEventListeners.add(listener);
187-
if (hasActiveCatalystInstance() || isBridgeless()) {
189+
}
190+
191+
public void addLifecycleEventListenerAndCheckState(final LifecycleEventListener listener) {
192+
mLifecycleEventListeners.add(listener);
193+
if (hasActiveCatalystInstance()) {
188194
switch (mLifecycleState) {
189195
case BEFORE_CREATE:
190196
case BEFORE_RESUME:

‎ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public FabricUIManager(
176176
mEventDispatcher = eventDispatcher;
177177
mShouldDeallocateEventDispatcher = false;
178178
mEventBeatManager = eventBeatManager;
179-
mReactApplicationContext.addLifecycleEventListener(this);
179+
mReactApplicationContext.addLifecycleEventListenerAndCheckState(this);
180180
}
181181

182182
public FabricUIManager(
@@ -189,7 +189,7 @@ public FabricUIManager(
189189
mEventDispatcher = new EventDispatcherImpl(reactContext);
190190
mShouldDeallocateEventDispatcher = true;
191191
mEventBeatManager = eventBeatManager;
192-
mReactApplicationContext.addLifecycleEventListener(this);
192+
mReactApplicationContext.addLifecycleEventListenerAndCheckState(this);
193193
}
194194

195195
// TODO (T47819352): Rename this to startSurface for consistency with xplat/iOS

‎ReactAndroid/src/main/java/com/facebook/react/modules/core/TimingModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public TimingModule(ReactApplicationContext reactContext, DevSupportManager devS
6868

6969
@Override
7070
public void initialize() {
71-
getReactApplicationContext().addLifecycleEventListener(this);
71+
getReactApplicationContext().addLifecycleEventListenerAndCheckState(this);
7272
HeadlessJsTaskContext headlessJsTaskContext =
7373
HeadlessJsTaskContext.getInstance(getReactApplicationContext());
7474
headlessJsTaskContext.addTaskEventListener(this);

‎ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public DeviceInfoModule(ReactApplicationContext reactContext) {
3737
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
3838
mFontScale = reactContext.getResources().getConfiguration().fontScale;
3939
mReactApplicationContext = reactContext;
40-
mReactApplicationContext.addLifecycleEventListener(this);
40+
mReactApplicationContext.addLifecycleEventListenerAndCheckState(this);
4141
}
4242

4343
public DeviceInfoModule(Context context) {

‎ReactAndroid/src/main/java/com/facebook/react/uimanager/ThemedReactContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public ThemedReactContext(
5656
}
5757

5858
@Override
59-
public void addLifecycleEventListener(LifecycleEventListener listener) {
60-
mReactApplicationContext.addLifecycleEventListener(listener);
59+
public void addLifecycleEventListenerAndCheckState(LifecycleEventListener listener) {
60+
mReactApplicationContext.addLifecycleEventListenerAndCheckState(listener);
6161
}
6262

6363
@Override

‎ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public UIManagerModule(
158158
mEventDispatcher,
159159
minTimeLeftInFrameForNonBatchedOperationMs);
160160

161-
reactContext.addLifecycleEventListener(this);
161+
reactContext.addLifecycleEventListenerAndCheckState(this);
162162
}
163163

164164
@Deprecated
@@ -180,7 +180,7 @@ public UIManagerModule(
180180
mEventDispatcher,
181181
minTimeLeftInFrameForNonBatchedOperationMs);
182182

183-
reactContext.addLifecycleEventListener(this);
183+
reactContext.addLifecycleEventListenerAndCheckState(this);
184184
}
185185

186186
/**

‎ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public int compare(Event lhs, Event rhs) {
104104

105105
public EventDispatcherImpl(ReactApplicationContext reactContext) {
106106
mReactContext = reactContext;
107-
mReactContext.addLifecycleEventListener(this);
107+
mReactContext.addLifecycleEventListenerAndCheckState(this);
108108
mReactEventEmitter = new ReactEventEmitter(mReactContext);
109109
}
110110

0 commit comments

Comments
 (0)