Skip to content

Conversation

@alsin
Copy link

@alsin alsin commented Oct 16, 2025

Motivation:

If a @Test method fails then potential VertxTestContext injected into a @AfterEach method (if any, of course) is not awaited.
For instance, a test might want to perform test data cleanup in a series of asynchronous operations in such a @AfterEach method and VertxTestContext could be used to gracefully wait for their end of operation. Unfortunately, as of now, if a test fails it does not wait for the test context injected into an after test method.

Conformance:

You should have signed the Eclipse Contributor Agreement as explained in https://github.com/eclipse/vert.x/blob/master/CONTRIBUTING.md
Please also make sure you adhere to the code style guidelines: https://github.com/vert-x3/wiki/wiki/Vert.x-code-style-guidelines

Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

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

Thanks for this PR @alsin

Please see comments inline. When updating the PR, please sign-off your commits (using the email that is registered at the Eclipse Fdn for your contributor agreement).

Comment on lines +183 to +190
final boolean isNotInAfterEachMethod = Optional.ofNullable(invocationContext)
.map(ReflectiveInvocationContext::getExecutable)
.map(executable -> executable.getAnnotation(AfterEach.class))
.isEmpty();

if (isNotInAfterEachMethod) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This might fix the problem for @AfterEach methods, but not for @AfterAll ones.

The extension creates a new VertxTestContext for each intercepted method. I think the criterion for waiting the completion of the context should be that the execution exception hasn't changed during the invocation

Copy link
Author

Choose a reason for hiding this comment

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

There's no such problem for @AfterAll - the extension context which is passed into

  public void interceptAfterAllMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {

does not contain the exception thrown in the @Test method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Can you please rework the test so that it passes?

Copy link
Author

@alsin alsin Oct 22, 2025

Choose a reason for hiding this comment

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

I don't think it's possible - the thing is it has to fail the VertxTestContext in the test method so that the bug occurs in the @AfterEach method and we have something to test. Otherwise, if the test context is succeeded, the bug never reveals itself in the @AfterEach. It's kind of a paradox - I don't really know how to test this properly to be honest as the test should fail in order to pass 🤔 What I can do is remove the test completely but then any possible regression could be overlooked in the future. Can you suggest me something here, please?

Copy link
Author

Choose a reason for hiding this comment

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

I think I might have an idea how to write such a test. Let me try on it, I'll let you know soon if I find a way :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, looking forward to it!

Copy link
Author

@alsin alsin Oct 23, 2025

Choose a reason for hiding this comment

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

Ok, I think I've got a working solution. Actually, I didn't notice that there are already some other JUnit tests in the project that are excluded from running by the surefire plugin using the @Tag solution but are run programmatically from another tests without those tags. I decided to go a bit different way using the @Disabled annotation which is then deactivated in another test. Please, check it out! Thank you!

@alsin alsin force-pushed the fix-context-ignorance-in-after-each branch 3 times, most recently from 5cf6865 to b41756b Compare October 22, 2025 16:28
@alsin alsin force-pushed the fix-context-ignorance-in-after-each branch from b41756b to cdec66d Compare October 22, 2025 16:30
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.

2 participants