WebWorkers: Add simple integration test
Summary: public Adds a simple integration test that verifies that a message can be posted to/from the worker andthat it's torn down properly. Reviewed By: lexs Differential Revision: D2815244 fb-gh-sync-id: 00c0d8933d785b2913d378c0589b2fbabf0d0edb
This commit is contained in:
parent
0be36a2c80
commit
e29eaaddc8
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.react.testing;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.facebook.react.bridge.BaseJavaModule;
|
||||||
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native module provides single method {@link #record} which records its single int argument
|
||||||
|
* in calls array
|
||||||
|
*/
|
||||||
|
public class IntRecordingModule extends BaseJavaModule {
|
||||||
|
|
||||||
|
private final List<Integer> mCalls = new ArrayList<>();
|
||||||
|
private final CountDownLatch mCountDownLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Recording";
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void record(int i) {
|
||||||
|
mCalls.add(i);
|
||||||
|
mCountDownLatch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
mCalls.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getCalls() {
|
||||||
|
return mCalls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void waitForFirstCall() {
|
||||||
|
try {
|
||||||
|
if (!mCountDownLatch.await(15000, TimeUnit.MILLISECONDS)) {
|
||||||
|
throw new RuntimeException("Timed out waiting for first call");
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
import android.support.test.InstrumentationRegistry;
|
import android.support.test.InstrumentationRegistry;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -27,6 +28,7 @@ import com.facebook.react.bridge.CatalystInstanceImpl;
|
||||||
import com.facebook.react.bridge.LifecycleEventListener;
|
import com.facebook.react.bridge.LifecycleEventListener;
|
||||||
import com.facebook.react.bridge.SoftAssertions;
|
import com.facebook.react.bridge.SoftAssertions;
|
||||||
import com.facebook.react.bridge.UiThreadUtil;
|
import com.facebook.react.bridge.UiThreadUtil;
|
||||||
|
import com.facebook.react.common.ApplicationHolder;
|
||||||
import com.facebook.react.common.futures.SimpleSettableFuture;
|
import com.facebook.react.common.futures.SimpleSettableFuture;
|
||||||
import com.facebook.react.modules.core.Timing;
|
import com.facebook.react.modules.core.Timing;
|
||||||
|
|
||||||
|
@ -155,6 +157,7 @@ public abstract class ReactIntegrationTestCase extends AndroidTestCase {
|
||||||
mBridgeIdleSignaler = new ReactBridgeIdleSignaler();
|
mBridgeIdleSignaler = new ReactBridgeIdleSignaler();
|
||||||
mInstance.addBridgeIdleDebugListener(mBridgeIdleSignaler);
|
mInstance.addBridgeIdleDebugListener(mBridgeIdleSignaler);
|
||||||
getContext().initializeWithInstance(mInstance);
|
getContext().initializeWithInstance(mInstance);
|
||||||
|
ApplicationHolder.setApplication((Application) getContext().getApplicationContext());
|
||||||
setupEvent.occur();
|
setupEvent.occur();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue