Skip to content

Commit 4dbed89

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Stop posting unnecessary work to threads in espresso.
Currently Espresso will post no-op empty runnables to a background thread pool for every interaction when running Espresso in a normal, non-remote environment. This is wasteful and causes some noise for leaked-thread detector facilities. This commit addresses this by adding an extra API to RemoteInteraction, so it only posts the remote commumnication runnable if its running in remote mode. PiperOrigin-RevId: 600526081
1 parent 36b7f78 commit 4dbed89

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

espresso/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The following artifacts were released:
2121
* Reference doc cleanup - document previously missing parameters, fix links, etc
2222
* Remove Kotlin StringKt calls from Java code
2323
* Remove all support for Android SDKs < 19. Minimum is API 19 (Android Kit Kat 4.4)
24+
* Stop posting empty tasks to background threads when running in non-remote mode
2425

2526
**New Features**
2627

espresso/core/java/androidx/test/espresso/ViewInteraction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public Void call() {
198198

199199
List<ListenableFuture<Void>> interactions = new ArrayList<>();
200200
interactions.add(postAsynchronouslyOnUiThread(performInteraction));
201-
if (!remoteInteraction.isRemoteProcess()) {
201+
if (!remoteInteraction.isRemoteProcess() && remoteInteraction.isRemoteClient()) {
202202
// Only the original process should submit remote interactionsList;
203203
interactions.add(
204204
remoteExecutor.submit(
@@ -352,7 +352,7 @@ public Void call() {
352352

353353
List<ListenableFuture<Void>> interactions = new ArrayList<>();
354354
interactions.add(postAsynchronouslyOnUiThread(checkInteraction));
355-
if (!remoteInteraction.isRemoteProcess()) {
355+
if (!remoteInteraction.isRemoteProcess() && remoteInteraction.isRemoteClient()) {
356356
// Only the original process should submit remote interactionsList;
357357
interactions.add(
358358
remoteExecutor.submit(

espresso/core/java/androidx/test/espresso/api/current_public.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ package androidx.test.espresso.remote {
788788
public interface RemoteInteraction {
789789
method public java.util.concurrent.Callable<java.lang.Void!>! createRemoteCheckCallable(org.hamcrest.Matcher<androidx.test.espresso.Root!>!, org.hamcrest.Matcher<android.view.View!>!, java.util.Map<java.lang.String!,android.os.IBinder!>!, androidx.test.espresso.ViewAssertion!);
790790
method public java.util.concurrent.Callable<java.lang.Void!>! createRemotePerformCallable(org.hamcrest.Matcher<androidx.test.espresso.Root!>!, org.hamcrest.Matcher<android.view.View!>!, java.util.Map<java.lang.String!,android.os.IBinder!>!, androidx.test.espresso.ViewAction!...);
791+
method public default boolean isRemoteClient();
791792
method public boolean isRemoteProcess();
792793
field public static final String BUNDLE_EXECUTION_STATUS = "executionStatus";
793794
}

espresso/core/java/androidx/test/espresso/remote/RemoteInteraction.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@
3333
public interface RemoteInteraction {
3434
static final String BUNDLE_EXECUTION_STATUS = "executionStatus";
3535

36-
/** @return {@code true} if the current Espresso instance running in a remote process. */
36+
/** Returns {@code true} if the current Espresso instance running in a remote process. */
3737
boolean isRemoteProcess();
3838

39+
/**
40+
* Returns {code true} if the current Espresso instance is communicating with another Espresso
41+
* instance in a remote process.
42+
*/
43+
default boolean isRemoteClient() {
44+
return false;
45+
}
46+
3947
/**
4048
* Creates a callable to run Espresso check interaction on remote processes
4149
*

espresso/core/javatests/androidx/test/espresso/ViewInteractionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ public Void call() throws Exception {
436436
when(mockViewFinder.getView()).thenThrow(noActivityResumed);
437437
// enable remote interaction
438438
when(mockRemoteInteraction.isRemoteProcess()).thenReturn(false);
439+
when(mockRemoteInteraction.isRemoteClient()).thenReturn(true);
439440
// noinspection unchecked
440441
when(mockRemoteInteraction.createRemoteCheckCallable(
441442
ArgumentMatchers.any(),
@@ -624,6 +625,7 @@ private void initWithRemoteInteraction() {
624625

625626
// enable remote interaction
626627
when(mockRemoteInteraction.isRemoteProcess()).thenReturn(false);
628+
when(mockRemoteInteraction.isRemoteClient()).thenReturn(true);
627629
}
628630

629631
private static final class BindableViewAction implements ViewAction, Bindable {

espresso/remote/java/androidx/test/espresso/remote/EspressoRemote.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ public synchronized boolean isRemoteProcess() {
173173
return isRemoteProcess;
174174
}
175175

176+
@Override
177+
public boolean isRemoteClient() {
178+
return !isRemoteProcess();
179+
}
180+
176181
/**
177182
* Creates a callable to run Espresso check interaction on remote processes
178183
*

0 commit comments

Comments
 (0)