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

MockMvc: afterCompletion is never called on CallableProcessingInterceptor and DeferredResultProcessingInterceptor [SPR-13615] #18193

Closed
spring-issuemaster opened this issue Oct 27, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Oct 27, 2015

João Cabrita opened SPR-13615 and commented

If I run the application, it's called correctly but, in MockMvc tests, it's never called.


Affects: 4.2.2

Reference URL: https://github.com/spring-projects/spring-framework-issues/tree/master/SPR-13615

Referenced from: commits spring-projects/spring-framework-issues@78fb08b, spring-projects/spring-framework-issues@e4ecbe9

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 27, 2015

Rossen Stoyanchev commented

Please provide an example of how the test is written.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 27, 2015

João Cabrita commented

I've added a link to the pull request for my reproduction example.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 29, 2015

Rossen Stoyanchev commented

Thanks for the detailed example.

The interceptors are called as a result of the async request being completed and the servlet container notifying any registered AsyncListener's. We are registered, however in this case there is no Servlet container and hence no notifications. I think can do it in MockMvc after performing the async dispatch if the request has an AsyncContext and asyncStarted=false.

In the mean time as a workaround you can call AsyncContext.complete() manually:

@Test
public void repro2() throws Exception {
    MvcResult r = mockMvc.perform(get("/dummyDeferred"))
        .andExpect(request().asyncStarted())
        .andReturn();
    mockMvc.perform(asyncDispatch(r)).andExpect(status().isOk());
    r.getRequest().getAsyncContext().complete();
    assertTrue(deferredResultInterceptor.executed.get());
}
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 9, 2015

João Cabrita commented

How rude of me, thank you for the workaround, it works.

I see that you also committed a "fix", thank you for taking the time to work on this and getting it done so quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.