Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using FailTestOnLeakRunListener fails to report back failures when using Android Test Orchestrator. #1046

Closed
runningcode opened this issue Jun 29, 2018 · 7 comments · Fixed by #1849

Comments

@runningcode
Copy link

runningcode commented Jun 29, 2018

When using LeakCanary with Android Test Orchestrator and FailTestOnLeakRunListener, the RunListener fails to report the failure back to the Test Orchestrator even though it finds the leak.

Here's a sample. Run TuPeuxPasTest:
https://github.com/runningcode/leakcanary/tree/no/test-orchestrator

This is actually a bug with Android Test Orchestrator, here is a sample repro:
https://github.com/runningcode/TestOrchBug

And filed this bug with android: https://issuetracker.google.com/issues/110978490
Reopened here: https://issuetracker.google.com/issues/154639612

@pyricau pyricau added this to the 1.6 milestone Jul 4, 2018
@pyricau
Copy link
Member

pyricau commented Jul 4, 2018

We should look at how failure reporting is implemented in the orchestrator.

@pyricau
Copy link
Member

pyricau commented Jul 20, 2018

Looks like orchestrator is just an APK: https://dl.google.com/dl/android/maven2/com/android/support/test/orchestrator/1.0.2/orchestrator-1.0.2.pom

The pom.xml has a dependency on com.android.support.test.services:test-services

https://dl.google.com/dl/android/maven2/com/android/support/test/services/test-services/1.0.2/test-services-1.0.2.pom

Which is also an APK and has no dependency.

@pyricau pyricau removed this from the 1.6 milestone Jul 20, 2018
@pyricau
Copy link
Member

pyricau commented Jul 20, 2018

We'll ship 1.6 as is for now, with the known issue that it doesn't work with the Android Test orchestrator, until we figure out exactly works / how it differs.

@balachandarlinks
Copy link

balachandarlinks commented Aug 9, 2018

AndroidTestOrchestrator runs every test in a separate test runner. So that a FailTestOnLeakRunListener will be created for each test. I created a feature request (https://issuetracker.google.com/issues/110768520) to add one time callbacks to AndroidTestOrchestrator to notify test run start/stop. Maybe it would help this scenario as well.

@pyricau pyricau added this to the 2.0 milestone Mar 30, 2019
@pyricau pyricau modified the milestones: 2.0-alpha-1, 2.0 Next Release May 1, 2019
@pyricau pyricau modified the milestones: 2.0-alpha-2, 2.0 Next Release May 21, 2019
@pyricau pyricau modified the milestones: 2.0-alpha-3, 2.0 Next Release Jul 4, 2019
@pyricau pyricau modified the milestones: 2.0-beta-1, 2.0 Next Release Jul 26, 2019
@pyricau pyricau modified the milestones: 2.0-beta-2, 2.0 Next Release Aug 2, 2019
@pyricau pyricau removed this from the 2.0 Next Release milestone Aug 22, 2019
@runningcode
Copy link
Author

Refiled the bug since the original was closed. Please star the issue here: https://issuetracker.google.com/issues/154639612

@pyricau
Copy link
Member

pyricau commented Apr 23, 2020

btw I started some exploration here: #1758

pyricau added a commit that referenced this issue Jun 4, 2020
With this change, FailTestOnLeakRunListener now hooks into AndroidJUnitRunner when a test run starts to detect if the tests are run by Android Test Orchestrator, in which case we take over the binder callback to send optionally send an extra failure when a leak is detected in test.

This works whether newRunListenerMode is false or true (ie whether OrchestratedInstrumentationListener runs before or after FailTestOnLeakRunListener).

When a test finishes without any failure, we intercept any "test finished" message, check for memory leaks, optionally send a "test failure" message then send the "test finished message". This intercepting is done assuming a single thread calls both listeners (see `org.junit.runner.notification.RunNotifier#wrapIfNotThreadSafe`).

As before with `Instrumentation.sendStatus()`, the current approach is tied to the test runner implementation details and might have to change to adapt to new `androidx.test:runner` versions.

Other change: FailTestOnLeakRunListener will wait up to 2 seconds for all activities to be destroyed before running leak detection, and otherwise proceed.

Fixes #1046
pyricau added a commit that referenced this issue Jun 4, 2020
With this change, FailTestOnLeakRunListener now hooks into AndroidJUnitRunner when a test run starts to detect if the tests are run by Android Test Orchestrator, in which case we take over the binder callback to send optionally send an extra failure when a leak is detected in test.

This works whether newRunListenerMode is false or true (ie whether OrchestratedInstrumentationListener runs before or after FailTestOnLeakRunListener).

When a test finishes without any failure, we intercept any "test finished" message, check for memory leaks, optionally send a "test failure" message then send the "test finished message". This intercepting is done assuming a single thread calls both listeners (see `org.junit.runner.notification.RunNotifier#wrapIfNotThreadSafe`).

As before with `Instrumentation.sendStatus()`, the current approach is tied to the test runner implementation details and might have to change to adapt to new `androidx.test:runner` versions.

Other change: FailTestOnLeakRunListener will wait up to 2 seconds for all activities to be destroyed before running leak detection, and otherwise proceed.

Fixes #1046
@pyricau pyricau added this to the 2.4 milestone Jun 4, 2020
@pyricau
Copy link
Member

pyricau commented Jun 4, 2020

Finally got something ready! #1849

pyricau added a commit that referenced this issue Jun 5, 2020
With this change, FailTestOnLeakRunListener now hooks into AndroidJUnitRunner when a test run starts to detect if the tests are run by Android Test Orchestrator, in which case we take over the binder callback to send optionally send an extra failure when a leak is detected in test.

This works whether newRunListenerMode is false or true (ie whether OrchestratedInstrumentationListener runs before or after FailTestOnLeakRunListener).

When a test finishes without any failure, we intercept any "test finished" message, check for memory leaks, optionally send a "test failure" message then send the "test finished message". This intercepting is done assuming a single thread calls both listeners (see `org.junit.runner.notification.RunNotifier#wrapIfNotThreadSafe`).

As before with `Instrumentation.sendStatus()`, the current approach is tied to the test runner implementation details and might have to change to adapt to new `androidx.test:runner` versions.

Other change: FailTestOnLeakRunListener will wait up to 2 seconds for all activities to be destroyed before running leak detection, and otherwise proceed.

Fixes #1046
pyricau added a commit that referenced this issue Jun 8, 2020
With this change, FailTestOnLeakRunListener now hooks into AndroidJUnitRunner when a test run starts to detect if the tests are run by Android Test Orchestrator, in which case we take over the binder callback to send optionally send an extra failure when a leak is detected in test.

This works whether newRunListenerMode is false or true (ie whether OrchestratedInstrumentationListener runs before or after FailTestOnLeakRunListener).

When a test finishes without any failure, we intercept any "test finished" message, check for memory leaks, optionally send a "test failure" message then send the "test finished message". This intercepting is done assuming a single thread calls both listeners (see `org.junit.runner.notification.RunNotifier#wrapIfNotThreadSafe`).

As before with `Instrumentation.sendStatus()`, the current approach is tied to the test runner implementation details and might have to change to adapt to new `androidx.test:runner` versions.

Other change: FailTestOnLeakRunListener will wait up to 2 seconds for all activities to be destroyed before running leak detection, and otherwise proceed.

Fixes #1046
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants