Fix mocking multiple http calls in the same function call (#6510)
* Fix mocking multiple http calls in the same function call Fixes an issue where a function call would perform more than one http request and wait for each to complete before proceeding. The `RequestId` comes from the length of the `requests` collection in the `OffchainState` and if a request is completed before the next one starts it will be removed and the "next expected" will be off by one. This PR tries to fix that by using a request counter that tracks how many requests have been performed so that we can `remove()` items from the `expected_requests` at the right index. I suspect that this is a sub-optimal soluton and perhaps requests and their mocks should live side by side in the same collection, e.g. in a tuple of `(PendingRequest, Option<ExpectedRequest>)`. * Update primitives/core/src/offchain/testing.rs Co-authored-by: Bernhard Schuster <[email protected]> * Update primitives/core/src/offchain/testing.rs Co-authored-by: Bernhard Schuster <[email protected]> * Panic on overflow * Update primitives/core/src/offchain/testing.rs Co-authored-by: Bastian Köcher <[email protected]> * Use a Deque and push/pop expected requests * fix test Co-authored-by: Bernhard Schuster <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
parent
ce02e1df
Please register or sign in to comment