You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which, as noted at the start, runs the #request middleware again.
The middleware handling was added waaay back in #111. Since the #request hook can amend the request headers & body, it makes sense that you'd want it to run before building & checking the webmock signature. But the circuitous control flow means that if the middleware has a side-effect (e.g., adding another callback), those side-effects will get triggered twice, which can lead to some really bizarre (and incorrect) behavior in the test suite.
The text was updated successfully, but these errors were encountered:
@ajvondrak thank you for investigating this and presenting the detailed explanation of the problem. Since you know the problem, do you perhaps also know how this can be fixed? If yes, then would you fancy submitting a PR with the fix?
Specifically, the
#request
methods are invoked in two places.EventMachine::HttpClient#connection_completed
: https://github.com/igrigorik/em-http-request/blob/157d5ff281c503656192825c388b28e7f35e04ce/lib/em-http/client.rb#L57-L59EventMachine::WebMockHttpClient#build_request_signature
:webmock/lib/webmock/http_lib_adapters/em_http_request_adapter.rb
Lines 169 to 171 in 382d84c
The request signature is built at the start of
EventMachine::WebMockHttpConnection#activate_connection
here:webmock/lib/webmock/http_lib_adapters/em_http_request_adapter.rb
Line 56 in 382d84c
This happens prior to duplicating the logic of
EventMachine::HttpConnection#activate_connection
(ref) to call#finalize_request
here:webmock/lib/webmock/http_lib_adapters/em_http_request_adapter.rb
Lines 60 to 69 in 382d84c
Then the
#finalize_request
call hits the superclassEventMachine::HttpConnection#finalize_request
, which adds a callback toEventMachine::HttpClient#connection_completed
: https://github.com/igrigorik/em-http-request/blob/157d5ff281c503656192825c388b28e7f35e04ce/lib/em-http/http_connection.rb#L159Which, as noted at the start, runs the
#request
middleware again.The middleware handling was added waaay back in #111. Since the
#request
hook can amend the request headers & body, it makes sense that you'd want it to run before building & checking the webmock signature. But the circuitous control flow means that if the middleware has a side-effect (e.g., adding another callback), those side-effects will get triggered twice, which can lead to some really bizarre (and incorrect) behavior in the test suite.The text was updated successfully, but these errors were encountered: