Skip to content

Commit

Permalink
Migration of RN-Android OSS tests to Android X
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Mar 17, 2019
1 parent 5613aa8 commit 8d5ac8d
Show file tree
Hide file tree
Showing 122 changed files with 1,433 additions and 431 deletions.
1 change: 1 addition & 0 deletions RNTester/android/app/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rn_android_binary(
rn_android_library(
name = "rntester-lib",
srcs = glob(["src/main/java/**/*.java"]),
is_androidx = True,
deps = [
":res",
react_native_dep("third-party/android/support/v4:lib-support-v4"),
Expand Down
3 changes: 3 additions & 0 deletions RNTester/android/app/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=androiddebugkey
MYAPP_RELEASE_STORE_PASSWORD=android
MYAPP_RELEASE_KEY_PASSWORD=android

android.useAndroidX=true
android.enableJetifier=true
7 changes: 4 additions & 3 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ android {
buildConfigField("boolean", "IS_INTERNAL_BUILD", "false")
buildConfigField("int", "EXOPACKAGE_FLAGS", "0")
testApplicationId("com.facebook.react.tests.gradle")
testInstrumentationRunner("android.support.test.runner.AndroidJUnitRunner")
testInstrumentationRunner("androidx.test.runner.AndroidJUnitRunner")
}

sourceSets.main {
Expand Down Expand Up @@ -337,8 +337,9 @@ dependencies {
testImplementation("org.robolectric:robolectric:${ROBOLECTRIC_VERSION}")

androidTestImplementation(fileTree(dir: "src/main/third-party/java/buck-android-support/", include: ["*.jar"]))
androidTestImplementation("com.android.support.test:runner:${ANDROID_SUPPORT_TEST_VERSION}")
androidTestImplementation("com.android.support.test:rules:${ANDROID_SUPPORT_TEST_VERSION}")
//TODO: Refactor to extract versions of androidx dependencies
androidTestImplementation("androidx.test:runner:1.1.0")
androidTestImplementation("androidx.test:rules:1.1.0")
androidTestImplementation("org.mockito:mockito-core:${MOCKITO_CORE_VERSION}")
}

Expand Down
3 changes: 3 additions & 0 deletions ReactAndroid/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ DOUBLE_CONVERSION_VERSION=1.1.6
FOLLY_VERSION=2018.10.22.00
GLOG_VERSION=0.3.5
JSC_VERSION=236355.1.1

android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</application>

<instrumentation
android:name="android.support.test.runner.AndroidJUnitRunner"
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.facebook.react.tests"
android:label="Buck runs instrumentation tests"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rn_android_library(
"network/**/*.java",
],
),
is_androidx = True,
visibility = [
"PUBLIC",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import androidx.fragment.app.FragmentActivity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.concurrent.TimeUnit;

import android.app.Application;
import android.support.test.InstrumentationRegistry;
import android.test.AndroidTestCase;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -164,7 +163,9 @@ public boolean waitForBridgeIdle(long millis) {
}

public void waitForIdleSync() {
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
return;
// TODO: re-enable after cleanup of android-x migration
//InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}

public void waitForBridgeAndUIIdle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import android.app.Instrumentation;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -120,12 +119,13 @@ public ReactInstanceManagerBuilder getReactInstanceManagerBuilder() {
}

public static ReactTestFactory getReactTestFactory() {
Instrumentation inst = InstrumentationRegistry.getInstrumentation();
if (!(inst instanceof ReactTestFactory)) {
// TODO: re-enable after cleanup of android-x migration
// Instrumentation inst = InstrumentationRegistry.getInstrumentation();
// if (!(inst instanceof ReactTestFactory)) {
return new DefaultReactTestFactory();
}

return (ReactTestFactory) inst;
// }
//
// return (ReactTestFactory) inst;
}

public static ReactTestFactory.ReactInstanceEasyBuilder catalystInstanceBuilder(
Expand All @@ -151,13 +151,14 @@ public CatalystInstance build() {
final CatalystInstance instance = builder.build();
testCase.initializeWithInstance(instance);
instance.runJSBundle();
InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
// TODO: re-enable after cleanup of android-x migration
// InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
// @Override
// public void run() {
ReactChoreographer.initialize();
instance.initialize();
}
});
// }
// });
testCase.waitForBridgeAndUIIdle();
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -34,93 +24,96 @@ public static void waitForBridgeAndUIIdle(
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!");
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ load(
rn_android_library(
name = "rule",
srcs = glob(["*.java"]),
is_androidx = True,
visibility = [
"PUBLIC",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import android.app.Activity;
import android.os.Build;
import android.support.test.rule.ActivityTestRule;
import androidx.test.rule.ActivityTestRule;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactPackage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_int
rn_android_library(
name = "tests",
srcs = glob(["*.java"]),
is_androidx = True,
visibility = [
"PUBLIC",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import android.widget.DatePicker;

import com.facebook.react.bridge.BaseJavaModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.support.v4.app.DialogFragment;
import androidx.fragment.app.DialogFragment;

import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.testing.ReactInstanceSpecForTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.support.v4.app.DialogFragment;
import androidx.fragment.app.DialogFragment;

import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.testing.ReactInstanceSpecForTest;
Expand Down
Loading

0 comments on commit 8d5ac8d

Please sign in to comment.