while working with the new extensions more, had is...
# wiremock-java
d
while working with the new extensions more, had issues, especially in the CI systems, that somehow feels like
afterComplete
are not processed timely. Can it happen that these events are processed after the response was sent and thus even after the next request is matched?
o
I need to check the code but it is plausible
d
can we somehow create a way to have events processed before the response is sent? e.g. finish all events for a serveevent before sending the response and/or having an extra event for "after" sending the response. With the state extension, I run into race conditions as the next request might rely on the state of the previous one.
o
It makes sense. As well as both sync and Async after-hooks
👍 1
t
Yes, that part is necessarily async as Jetty uses non-blocking IO and
afterComplete
only occurs after the response has been fully sent. So there’s no way to make this synchronous unfortunately. Jetty did have a blocking IO connector a few versions ago but they dropped it IIRC. I suggest using
afterMatch
if you can as this is (or should be!) reliably synchronous.
d
is the response already available in
afterMatch
?
t
The response definition is. Would that work for you?
d
will try - should at least minimize the window then
t
Wonder if we should consider adding
afterResponseRendered
d
ah right - definition != rendered
would need the rendered version
or, to make it a pair:
beforeComplete
?
t
I feel like
beforeComplete
is a bit ambiguous i.e. how far before complete are we?
I’m curious why you need the rendered response - is this because you need to be able to capture bits of it to store in state variables?
d
when you e.g. create a new entity in a CRUD API, the response can contain a randomly generated ID. This ID is used in the next GET. One use case of the state extension is to retrieve data based on this ID, therefore I need to have it available for recording a state.
t
OK, makes sense. I’m looking at adding a new event as we discussed. Think I might call it
beforeResponseSent
as the best place to call it seems to be after response rendering + all other activities have taken place. Does this seem reasonable to you?
d
sounds good. That event would still be async, wouldn't it?
t
No, at that point we can still do it synchronously
d
nice
t
It’s the pushing bytes out over the (NIO) network connector that’s async
@Dirk Bolte this look like it’ll do what you want? https://github.com/wiremock/wiremock/pull/2295
d
looks good - will give it a try soon
👍 1
t
I’ll merge and release it in a new beta build
👍 1