mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
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 <bernhard@ahoi.io> * Update primitives/core/src/offchain/testing.rs Co-authored-by: Bernhard Schuster <bernhard@ahoi.io> * Panic on overflow * Update primitives/core/src/offchain/testing.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Use a Deque and push/pop expected requests * fix test Co-authored-by: Bernhard Schuster <bernhard@ahoi.io> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -497,9 +497,7 @@ fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
|
||||
let mut ext = TestExternalities::default();
|
||||
let (offchain, state) = testing::TestOffchainExt::new();
|
||||
ext.register_extension(OffchainExt::new(offchain));
|
||||
state.write().expect_request(
|
||||
0,
|
||||
testing::PendingRequest {
|
||||
state.write().expect_request(testing::PendingRequest {
|
||||
method: "POST".into(),
|
||||
uri: "http://localhost:12345".into(),
|
||||
body: vec![1, 2, 3, 4],
|
||||
|
||||
Reference in New Issue
Block a user