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

Trim stack trace. #1028

Merged
merged 9 commits into from
Feb 6, 2017
Merged

Trim stack trace. #1028

merged 9 commits into from
Feb 6, 2017

Conversation

kcooney
Copy link
Member

@kcooney kcooney commented Nov 8, 2014

This is just some ideas I had for fixing #669. I haven't written tests yet; just wanted early feedback.

@kcooney kcooney force-pushed the trim-stack-trace branch 2 times, most recently from 81fe75d to 11b0e34 Compare November 8, 2014 22:33
*/
public String getFilteredTrace() {
Throwable exception = getException();
String fullTrace = getTrace(exception);
Copy link
Member

Choose a reason for hiding this comment

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

The above two lines can be replaced with a call to getTrace().

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@marcphilipp
Copy link
Member

BaseTestRunner.getFilteredTrace() would have to be removed then, right?

@marcphilipp
Copy link
Member

@kcooney I like the general idea!

@kcooney kcooney mentioned this pull request Nov 20, 2014
@kcooney kcooney force-pushed the trim-stack-trace branch 2 times, most recently from 44e12ce to 4f7c311 Compare March 29, 2015 22:28
@kcooney
Copy link
Member Author

kcooney commented Mar 29, 2015

I finally found time to work on this. I added lots of tests. Please take another look.

@marcphilipp I'm not sure what you meant by "BaseTestRunner.getFilteredTrace() would have to be removed then, right?"

@kcooney kcooney force-pushed the trim-stack-trace branch 2 times, most recently from ea663e2 to 7b174b5 Compare March 29, 2015 22:34
@marcphilipp
Copy link
Member

@kcooney I don't recall what I meant by that either, sorry. Never mind, then. LGTM so far, needs a bit of refactoring IMHO since it contains a few long, complex methods.

@kcooney
Copy link
Member Author

kcooney commented May 2, 2015

@marcphilipp the only really long method is StackTraces.trimStackTrace() and I don't see a clean way to break it up. Did you have something particular in mind?

static String trimStackTrace(String extracedExceptionMessage, String fullTrace) {
StringBuilder trimmedTrace = new StringBuilder(extracedExceptionMessage);
BufferedReader reader = new BufferedReader(
new StringReader(fullTrace.substring(extracedExceptionMessage.length())));

Choose a reason for hiding this comment

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

extraced -> extracted - typo

@kcooney
Copy link
Member Author

kcooney commented May 12, 2015

I extracted a method, and added more test cases. PTAL

If it looks good, I want to squash commits before merging this pull.

@kcooney
Copy link
Member Author

kcooney commented May 13, 2015

BTW, this pull won't affect the functionality of Maven (I checked), and won't likely affect Gradle. It only affects users of TextListener. The only way I can think of to get this behavior in Maven and Gradle would be for us to modify the stack trace in the exception itself.

@kcooney
Copy link
Member Author

kcooney commented Jun 3, 2015

I've made some more changes

  • Removed the changes to the JUnit 3 code. Anyone using that code can't run JUnit4-style tests, so it isn't worth potentially breaking someone
  • Removing that dependency allowed me to simplify the code
  • I also made the tests use actual stack traces, instead of fake ones hard-coded in the code. This caught a few bugs.

PTAL

In parallel, I'm experimenting with changing the actual stack trace of the thrown exception. If that works, that solution would cause the stack traces to be trimmed in Maven and Gradle

@marcphilipp
Copy link
Member

Before trimming the stacktrace for Maven/Gradle, I think we should ask someone from each project if that's something they'd appreciate, shouldn't we?

@kcooney
Copy link
Member Author

kcooney commented Jul 3, 2015

@marcphilipp I would be more interested in the feedback of Maven or Gradle users that also use JUnit. I don't think we need to reach out to the Maven or Gradle teams unless we think we would break them.

If we change the actual stack trace itself, I would be worried about breaking IDEs that already do this trimming.

The change as-is won't help many users

@kcooney
Copy link
Member Author

kcooney commented Jan 30, 2017

I was reviewing old pool requests, and took another look at this.

Maven Surefire already has an option (enabled, by default) to trim JUnit stack traces. I think I didn't realize this before since often the stack traces I see from running JUnit tests are from JUnit tests that run other JUnit tests.

In any case, I'd like to merge this. I've merged from master, and the tests pass locally. I also moved getTrimmedStackTrace() to the Throwables class (which I don't think existed at the time when I wrote this pull)

@marcphilipp any objections to merging this?

@kcooney kcooney added the 4.13 label Jan 30, 2017
Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

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

LGTM!

@kcooney kcooney merged commit ead2fe7 into junit-team:master Feb 6, 2017
@kcooney kcooney deleted the trim-stack-trace branch May 16, 2017 04:50
@kcooney kcooney modified the milestone: 4.13 Aug 6, 2017
sebasjm pushed a commit to sebasjm/junit4 that referenced this pull request Mar 11, 2018
Update TextListener to trim stack traces.

Fixes junit-team#669
copybara-service bot pushed a commit to android/android-test that referenced this pull request Sep 16, 2020
… classic/non-orchestrator modes.

This change should clean up test failure reporting by:
  - Remove test runner framework related stack frames
  - Truncate stack traces to a 64KB size when running under orchestrator
    to attempt to avoid binder transaction limits.
    This limit is already enforced when running in classic/non-orchestrator mode

JUnit 4.13 has a really nice getTrimmedStackTrace feature, but androidx.test
is fixed to 4.12 for the time being. So as a temporary workaround, copy
the relevant JUnit change junit-team/junit4#1028 into this project.

Fixes #729, and hopefully #269

PiperOrigin-RevId: 329797783
copybara-service bot pushed a commit to android/android-test that referenced this pull request Sep 16, 2020
… classic/non-orchestrator modes.

This change should clean up test failure reporting by:
  - Remove test runner framework related stack frames
  - Truncate stack traces to a 64KB size when running under orchestrator
    to attempt to avoid binder transaction limits.
    This limit is already enforced when running in classic/non-orchestrator mode

JUnit 4.13 has a really nice getTrimmedStackTrace feature, but androidx.test
is fixed to 4.12 for the time being. So as a temporary workaround, copy
the relevant JUnit change junit-team/junit4#1028 into this project.

Fixes #729, and hopefully #269

PiperOrigin-RevId: 329797783
copybara-service bot pushed a commit to android/android-test that referenced this pull request Sep 16, 2020
… classic/non-orchestrator modes.

This change should clean up test failure reporting by:
  - Remove test runner framework related stack frames
  - Truncate stack traces to a 64KB size when running under orchestrator
    to attempt to avoid binder transaction limits.
    This limit is already enforced when running in classic/non-orchestrator mode

JUnit 4.13 has a really nice getTrimmedStackTrace feature, but androidx.test
is fixed to 4.12 for the time being. So as a temporary workaround, copy
the relevant JUnit change junit-team/junit4#1028 into this project.

Fixes #729, and hopefully #269

PiperOrigin-RevId: 329797783
copybara-service bot pushed a commit to android/android-test that referenced this pull request Sep 16, 2020
… classic/non-orchestrator modes.

This change should clean up test failure reporting by:
  - Remove test runner framework related stack frames
  - Truncate stack traces to a 64KB size when running under orchestrator
    to attempt to avoid binder transaction limits.
    This limit is already enforced when running in classic/non-orchestrator mode

JUnit 4.13 has a really nice getTrimmedStackTrace feature, but androidx.test
is fixed to 4.12 for the time being. So as a temporary workaround, copy
the relevant JUnit change junit-team/junit4#1028 into this project.

Fixes #729, and hopefully #269

PiperOrigin-RevId: 332051125
rauljurado620 added a commit to rauljurado620/test-android-project that referenced this pull request Mar 24, 2022
… classic/non-orchestrator modes.

This change should clean up test failure reporting by:
  - Remove test runner framework related stack frames
  - Truncate stack traces to a 64KB size when running under orchestrator
    to attempt to avoid binder transaction limits.
    This limit is already enforced when running in classic/non-orchestrator mode

JUnit 4.13 has a really nice getTrimmedStackTrace feature, but androidx.test
is fixed to 4.12 for the time being. So as a temporary workaround, copy
the relevant JUnit change junit-team/junit4#1028 into this project.

Fixes #729, and hopefully #269

PiperOrigin-RevId: 332051125
aristotle0x01 pushed a commit to aristotle0x01/junit4 that referenced this pull request Jun 27, 2022
Update TextListener to trim stack traces.

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

Successfully merging this pull request may close these issues.

4 participants