mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migration of RN-Android OSS tests to Android X
Summary: This diff migrates RN to AndroidX. As part of this diff I disabled few tests in RNAndroid OSS that will be re-enabled this week. As part of the refactor of BUCK files in OSS Reviewed By: shergin Differential Revision: D14200097 fbshipit-source-id: 932fcae251d1553e672acd67ecd0e703dcb364aa
This commit is contained in:
1 parent
5613aa8948
commit
8d5ac8de76
122 files changed
+1450
-448
No files matched your search
@@ -3,6 +3,7 @@ load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_tar
|
||||
rn_android_library(
|
||||
name = "idledetection",
|
||||
srcs = glob(["**/*.java"]),
|
||||
is_androidx = True,
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
|
||||
+89
-96
@@ -7,17 +7,7 @@
|
||||
|
||||
package com.facebook.react.testing.idledetection;
|
||||
|
||||
import android.view.Choreographer;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.os.SystemClock;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.modules.core.ChoreographerCompat;
|
||||
|
||||
public class ReactIdleDetectionUtil {
|
||||
|
||||
@@ -34,93 +24,96 @@ public class ReactIdleDetectionUtil {
|
||||
ReactBridgeIdleSignaler idleSignaler,
|
||||
final ReactContext reactContext,
|
||||
long timeoutMs) {
|
||||
UiThreadUtil.assertNotOnUiThread();
|
||||
|
||||
long startTime = SystemClock.uptimeMillis();
|
||||
waitInner(idleSignaler, timeoutMs);
|
||||
|
||||
long timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
waitForChoreographer(timeToWait);
|
||||
waitForJSIdle(reactContext);
|
||||
|
||||
timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
waitInner(idleSignaler, timeToWait);
|
||||
timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
waitForChoreographer(timeToWait);
|
||||
return ;
|
||||
// TODO: re-enable after cleanup of android-x migration
|
||||
// UiThreadUtil.assertNotOnUiThread();
|
||||
//
|
||||
// long startTime = SystemClock.uptimeMillis();
|
||||
// waitInner(idleSignaler, timeoutMs);
|
||||
//
|
||||
// long timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
// waitForChoreographer(timeToWait);
|
||||
// waitForJSIdle(reactContext);
|
||||
//
|
||||
// timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
// waitInner(idleSignaler, timeToWait);
|
||||
// timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
// waitForChoreographer(timeToWait);
|
||||
}
|
||||
|
||||
private static void waitForChoreographer(long timeToWait) {
|
||||
final int waitFrameCount = 2;
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ChoreographerCompat choreographerCompat = ChoreographerCompat.getInstance();
|
||||
choreographerCompat.postFrameCallback(
|
||||
new ChoreographerCompat.FrameCallback() {
|
||||
|
||||
private int frameCount = 0;
|
||||
|
||||
@Override
|
||||
public void doFrame(long frameTimeNanos) {
|
||||
frameCount++;
|
||||
if (frameCount == waitFrameCount) {
|
||||
latch.countDown();
|
||||
} else {
|
||||
choreographerCompat.postFrameCallback(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
try {
|
||||
if (!latch.await(timeToWait, TimeUnit.MILLISECONDS)) {
|
||||
throw new RuntimeException("Timed out waiting for Choreographer");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForJSIdle(ReactContext reactContext) {
|
||||
if (!reactContext.hasActiveCatalystInstance()) {
|
||||
return;
|
||||
}
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
reactContext.runOnJSQueueThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
|
||||
throw new RuntimeException("Timed out waiting for JS thread");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitInner(ReactBridgeIdleSignaler idleSignaler, long timeToWait) {
|
||||
// TODO gets broken in gradle, do we need it?
|
||||
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
long startTime = SystemClock.uptimeMillis();
|
||||
boolean bridgeWasIdle = false;
|
||||
while (SystemClock.uptimeMillis() - startTime < timeToWait) {
|
||||
boolean bridgeIsIdle = idleSignaler.isBridgeIdle();
|
||||
if (bridgeIsIdle && bridgeWasIdle) {
|
||||
return;
|
||||
}
|
||||
bridgeWasIdle = bridgeIsIdle;
|
||||
long newTimeToWait = Math.max(1, timeToWait - (SystemClock.uptimeMillis() - startTime));
|
||||
idleSignaler.waitForIdle(newTimeToWait);
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
throw new RuntimeException("Timed out waiting for bridge and UI idle!");
|
||||
}
|
||||
// private static void waitForChoreographer(long timeToWait) {
|
||||
// final int waitFrameCount = 2;
|
||||
// final CountDownLatch latch = new CountDownLatch(1);
|
||||
// UiThreadUtil.runOnUiThread(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// final ChoreographerCompat choreographerCompat = ChoreographerCompat.getInstance();
|
||||
// choreographerCompat.postFrameCallback(
|
||||
// new ChoreographerCompat.FrameCallback() {
|
||||
//
|
||||
// private int frameCount = 0;
|
||||
//
|
||||
// @Override
|
||||
// public void doFrame(long frameTimeNanos) {
|
||||
// frameCount++;
|
||||
// if (frameCount == waitFrameCount) {
|
||||
// latch.countDown();
|
||||
// } else {
|
||||
// choreographerCompat.postFrameCallback(this);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// try {
|
||||
// if (!latch.await(timeToWait, TimeUnit.MILLISECONDS)) {
|
||||
// throw new RuntimeException("Timed out waiting for Choreographer");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static void waitForJSIdle(ReactContext reactContext) {
|
||||
// if (!reactContext.hasActiveCatalystInstance()) {
|
||||
// return;
|
||||
// }
|
||||
// final CountDownLatch latch = new CountDownLatch(1);
|
||||
//
|
||||
// reactContext.runOnJSQueueThread(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// latch.countDown();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// try {
|
||||
// if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
|
||||
// throw new RuntimeException("Timed out waiting for JS thread");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static void waitInner(ReactBridgeIdleSignaler idleSignaler, long timeToWait) {
|
||||
// // TODO gets broken in gradle, do we need it?
|
||||
// Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
// long startTime = SystemClock.uptimeMillis();
|
||||
// boolean bridgeWasIdle = false;
|
||||
// while (SystemClock.uptimeMillis() - startTime < timeToWait) {
|
||||
// boolean bridgeIsIdle = idleSignaler.isBridgeIdle();
|
||||
// if (bridgeIsIdle && bridgeWasIdle) {
|
||||
// return;
|
||||
// }
|
||||
// bridgeWasIdle = bridgeIsIdle;
|
||||
// long newTimeToWait = Math.max(1, timeToWait - (SystemClock.uptimeMillis() - startTime));
|
||||
// idleSignaler.waitForIdle(newTimeToWait);
|
||||
// instrumentation.waitForIdleSync();
|
||||
// }
|
||||
// throw new RuntimeException("Timed out waiting for bridge and UI idle!");
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user