From 98e20112ca4ab70f2e3e01556d699dd0e64085fd Mon Sep 17 00:00:00 2001 From: Nikita Khateev Date: Mon, 18 Mar 2019 15:38:43 +0300 Subject: [PATCH] Make libindy call ledger two times on single request on first time Signed-off-by: Nikita Khateev --- libindy/src/services/pool/pool.rs | 29 ++++++++++++++++++++ libindy/src/services/pool/request_handler.rs | 1 + 2 files changed, 30 insertions(+) diff --git a/libindy/src/services/pool/pool.rs b/libindy/src/services/pool/pool.rs index 72837fa550..8fb2a530aa 100644 --- a/libindy/src/services/pool/pool.rs +++ b/libindy/src/services/pool/pool.rs @@ -1124,6 +1124,35 @@ mod tests { test::cleanup_storage(); } + #[test] + pub fn pool_wrapper_sends_requests_to_two_nodes() { + test::cleanup_storage(); + + ProtocolVersion::set(2); + _write_genesis_txns(); + + let req = json!({ + "reqId": 1, + "operation": { + "type": "105" + } + }).to_string(); + + let p: PoolSM = PoolSM::new(Rc::new(RefCell::new(MockNetworker::new(0, 0, vec![]))), POOL, 1, 0, 0); + let p = p.handle_event(PoolEvent::CheckCache(1)); + let p = p.handle_event(PoolEvent::Synced(MerkleTree::from_vec(vec![]).unwrap())); + let p = p.handle_event(PoolEvent::SendRequest(3, req, None, None)); + assert_match!(PoolState::Active(_), p.state); + match p.state { + PoolState::Active(state) => { + assert_eq!(state.networker.borrow().events.len(), 2); + } + _ => assert!(false) + }; + + test::cleanup_storage(); + } + #[test] pub fn pool_wrapper_active_node_reply_works_for_no_request() { test::cleanup_storage(); diff --git a/libindy/src/services/pool/request_handler.rs b/libindy/src/services/pool/request_handler.rs index 5f9dba974e..7ce7981a82 100644 --- a/libindy/src/services/pool/request_handler.rs +++ b/libindy/src/services/pool/request_handler.rs @@ -267,6 +267,7 @@ impl RequestSM { } } RequestEvent::CustomSingleRequest(msg, req_id) => { + state.networker.borrow_mut().process_event(Some(NetworkerEvent::SendOneRequest(msg.clone(), req_id.clone(), timeout))); state.networker.borrow_mut().process_event(Some(NetworkerEvent::SendOneRequest(msg, req_id, timeout))); (RequestState::Single(state.into()), None) }