Skip to content

Increase InstrumentationResultPrinter.MAX_TRACE_SIZE #711

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

Merged
merged 1 commit into from
Sep 2, 2020

Conversation

pyricau
Copy link
Contributor

@pyricau pyricau commented Aug 7, 2020

This change increases InstrumentationResultPrinter.MAX_TRACE_SIZE from 65,536 bytes to 131,072 bytes, giving more room for long stacktraces (think RxJava and also view hierarchy logged as part of the trace message).

Also attempts to fallback to getTrimmedTrace() before actively trimming the trace at a random point.

@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@pyricau
Copy link
Contributor Author

pyricau commented Aug 7, 2020

Damn, I did sign the corporate CLA with my work email but Github online edit picked my personal email.

@bohsen
Copy link
Contributor

bohsen commented Aug 25, 2020

@brettchabot Friendly bump. This would be a welcome change also for projects using MaterialComponents. As their View-hierarchies are very large.

@@ -45,7 +45,7 @@

private static final String TAG = "InstrumentationResultPrinter";

@VisibleForTesting static final int MAX_TRACE_SIZE = 32 * 1024;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned this change is risky. It looks like the reason this limit exists is to prevent going over the binder IPC limit. It would seem like increasing the trace size would increase the chances of that occurring.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the binder maximum size was 1 MB.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right but I think it is possible that multiple stack traces will get sent in one binder transaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any value here is risky, in any direction we go. Decreasing max means shorter stacktraces => Espresso is less useful. Increasing the max means more risk of hitting the binder max.

What if this didn't already have a value today, how would we pick a value? 65,536 bytes is super conservative, but 131,072 bytes is also very conservative. To send multiple stacktraces at the same time you'd need to run tests in parallel and you'd need them to fail and you'd need long stacktraces for each. Isn't that a bit far fetched?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am under the impression that multiple stack traces can get sent in one transaction even under normal conditions. Even with this trace limit in place, there are user complaints about binder size transaction errors.
#269

Long term we hope to move away from using binder to communicate test results.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be hard to impose a limit on the aggregated size rather than individuals? If the cumulative stack trace size is big in one binder transaction, then stop adding more stack traces. This way, the common usefulness will increase (developer running a single test, tying to reproduce an issue and not seeing stack currently), while other cases will have more data too, but with some stacks fully missing.

Copy link
Contributor

@bohsen bohsen Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed change is targeting InstrumentationResultPrinter, not OrchestrationResultPrinter/OrchestrationXmlTestRunListener which the linked issues IMO clearly shows has issues.
Also OrchestrationResultPrinter/OrchestrationXmlTestRunListener do not impose any limits on the MAX_TRACE_SIZE although the OrchestrationResultPrinter-javadoc states:

...
A line by line reimplementation of {@link
androidx.test.internal.runner.listener.InstrumentationResultPrinter}
...

(maybe they actually should)

And they have no dependency on InstrumentationResultPrinter from what I can tell.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool. Thanks for all the investigation everyone. There have been reports of non-orchestrator-using users hitting binder transaction issues as well, but I suspect they were making heavy use of metrics. This change sounds reasonable but I'd like to do a bit more investigation with those users. I'm pretty slammed this week but will report back next week.

@brettchabot
Copy link
Collaborator

@pyricau would you be able to sign the CLA? thanks

@googlebot
Copy link
Collaborator

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@pyricau
Copy link
Contributor Author

pyricau commented Aug 30, 2020

Amended the commit to replace author with my work email, CLA ✅

TAG,
String.format("Stack trace too long, trimmed to first %s characters.", MAX_TRACE_SIZE));
trace = trace.substring(0, MAX_TRACE_SIZE) + "\n";
trace = failure.getTrimmedTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately it looks like getTrimmedTrace is only available in JUnit 4.13. Androidx.test still uses junit 4.12.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Should I remove it? Add a reflection check to see if the method is available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a failure at the end of a test, the performance penalty shouldn't matter. Your call!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove for now, but add a TODO to use it.

I have always wanted to see stack traces trimmed and I'm stoked to see such a method available, but JUnit upgrades can be onerous , so let's pursue that separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #729

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated branch with just the value change.

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

Successfully merging this pull request may close these issues.

5 participants