-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add a check to enforce alwaysRun = true on test after-methods #16741
Add a check to enforce alwaysRun = true on test after-methods #16741
Conversation
708506f
to
2fa9b41
Compare
Hm, it works weird. It doesn't fail any tests, just makes it not run any of them at all:
@hashhar do you have any exprience with these listeners? |
That's expected and what all our listeners do. See |
That's definitely the goal to make it very clear (by failing the tests?). I was following existing listeners, some of which also throw an exception. I was expecting that it would be more visible. |
Oh, in terms of how good the error message looks - I agree it's not ideal but that's the best we can do within the limitations of Surefire. |
I would say it's even less than not ideal, because an exception in the listener makes it skip all tests :) |
71d0918
to
85d4938
Compare
OK, now it works very loudly ;)
Thanks @hashhar |
This attribute says that this after-method will get executed even if the methods executed previously failed or were skipped. Note that it also applies to skipped test methods, so if the tests were skipped for some reason, the cleanup won't run. This attribute will ensure that the clean-up will run even in this case. Failure to run clean up may cause secondary effects, especially our resource leak detector; failure on this will in turn mask other errors, the ones which caused the tests to be skipped in the first place.
85d4938
to
fa3a618
Compare
...sting-services/src/test/java/io/trino/testng/services/TestReportAfterMethodNotAlwaysRun.java
Show resolved
Hide resolved
fa3a618
to
48c7333
Compare
...sting-services/src/test/java/io/trino/testng/services/TestReportAfterMethodNotAlwaysRun.java
Outdated
Show resolved
Hide resolved
48c7333
to
1153f57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good but I'll defer to @findepi as the listener expert.
private static final Set<AnnotationPredicate<?>> AFTER_ANNOTATIONS = ImmutableSet.of( | ||
new AnnotationPredicate<>(AfterTest.class, not(AfterTest::alwaysRun)), | ||
new AnnotationPredicate<>(AfterMethod.class, not(AfterMethod::alwaysRun)), | ||
new AnnotationPredicate<>(AfterClass.class, not(AfterClass::alwaysRun)), | ||
new AnnotationPredicate<>(AfterSuite.class, not(AfterSuite::alwaysRun)), | ||
new AnnotationPredicate<>(AfterGroups.class, not(AfterGroups::alwaysRun))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the predicate doesn't look for "after annotations". it looks for "after annotations that lack certain attribute"
AFTER_ANNOTATIONS -> VIOLATIONS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, changed
See the previous commit for details. This check will enforce that the `alwaysRun = true` is present.
1153f57
to
bdb3cab
Compare
Thank you @ksobolew |
Description
Turns out that the
@AfterX
methods do not get executed by default if any of the previous methods failed or were skipped - and that includes the test methods as well. So if any of the tests is skipped, cleanup for the test may also be skipped. ThealwaysRun = true
annotation enforces that the cleanup method always gets executed.Additional context and related issues
The failure to run the cleanup method may cause the resource leak detector to trigger and mask the actual cause the test was skipped.
Release notes
(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text: