Skip to content

Commit 6c2d53d

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Remove tracing from Espresso.onIdle.
Espresso.onIdle can be called many times through the life of a test, creating memory issues for long running tests and providing questionable value. With this commit, the `Espresso.onIdle` method no longer creates a tracing span. Corresponding tests for the span are also removed. PiperOrigin-RevId: 833388360
1 parent 299e4c4 commit 6c2d53d

File tree

3 files changed

+30
-37
lines changed

3 files changed

+30
-37
lines changed

espresso/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following artifacts were released:
1818

1919
* Replace now-unnecessary reflection from TestLooperManagerCompat when using Android SDK 36 APIs
2020
* Don't suppress AppNotIdleException if dumpThreadStates throws.
21+
* Remove Espresso.onIdle tracing
2122

2223
**New Features**
2324

espresso/core/java/androidx/test/espresso/Espresso.java

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -323,39 +323,37 @@ private static void waitUntilNextFrame(int times) {
323323
* @throws AppNotIdleException when app does not go Idle within the master policies timeout.
324324
*/
325325
public static <T> T onIdle(Callable<T> action) {
326-
try (Span ignored = tracer.beginSpan("Espresso.onIdle")) {
327-
if (Thread.currentThread().equals(Looper.getMainLooper().getThread())) {
328-
BASE.controlledLooper().drainMainThreadUntilIdle();
329-
BASE.uiController().loopMainThreadUntilIdle();
330-
try {
331-
return action.call();
332-
} catch (Exception e) {
333-
throw new RuntimeException("Callable action in onIdle reported an exception.", e);
334-
}
335-
}
336-
FutureTask<T> actionTask = new FutureTask<>(action);
337-
ListenableFutureTask<Void> idleFuture =
338-
ListenableFutureTask.create(
339-
() -> {
340-
BASE.uiController().loopMainThreadUntilIdle();
341-
return null;
342-
});
343-
Executor mainThreadExecutor = BASE.mainThreadExecutor();
344-
idleFuture.addListener(actionTask, mainThreadExecutor);
345-
mainThreadExecutor.execute(idleFuture);
326+
if (Thread.currentThread().equals(Looper.getMainLooper().getThread())) {
346327
BASE.controlledLooper().drainMainThreadUntilIdle();
347-
328+
BASE.uiController().loopMainThreadUntilIdle();
348329
try {
349-
idleFuture.get();
350-
return actionTask.get();
351-
} catch (InterruptedException ie) {
352-
throw new RuntimeException(ie);
353-
} catch (ExecutionException ee) {
354-
if (ee.getCause() instanceof AppNotIdleException) {
355-
throw (AppNotIdleException) ee.getCause();
356-
} else {
357-
throw new RuntimeException(ee);
358-
}
330+
return action.call();
331+
} catch (Exception e) {
332+
throw new RuntimeException("Callable action in onIdle reported an exception.", e);
333+
}
334+
}
335+
FutureTask<T> actionTask = new FutureTask<>(action);
336+
ListenableFutureTask<Void> idleFuture =
337+
ListenableFutureTask.create(
338+
() -> {
339+
BASE.uiController().loopMainThreadUntilIdle();
340+
return null;
341+
});
342+
Executor mainThreadExecutor = BASE.mainThreadExecutor();
343+
idleFuture.addListener(actionTask, mainThreadExecutor);
344+
mainThreadExecutor.execute(idleFuture);
345+
BASE.controlledLooper().drainMainThreadUntilIdle();
346+
347+
try {
348+
idleFuture.get();
349+
return actionTask.get();
350+
} catch (InterruptedException ie) {
351+
throw new RuntimeException(ie);
352+
} catch (ExecutionException ee) {
353+
if (ee.getCause() instanceof AppNotIdleException) {
354+
throw (AppNotIdleException) ee.getCause();
355+
} else {
356+
throw new RuntimeException(ee);
359357
}
360358
}
361359
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,6 @@ public void onData_throwsFromScenarioOnActivity() {
428428
@Test
429429
public void onIdle_worksFromScenarioOnActivity() {
430430
rule.getScenario().onActivity(activity -> onIdle());
431-
432-
assertThat(
433-
tracer.getSpans(), contains("beginSpan: Espresso.onIdle", "+-endSpan: Espresso.onIdle"));
434431
}
435432

436433
@Test
@@ -445,9 +442,6 @@ public void onIdle_worksFromMainThread() throws Exception {
445442
});
446443

447444
latch.await();
448-
449-
assertThat(
450-
tracer.getSpans(), contains("beginSpan: Espresso.onIdle", "+-endSpan: Espresso.onIdle"));
451445
}
452446

453447
private static class DummyIdlingResource implements IdlingResource {

0 commit comments

Comments
 (0)