get tests compiling
This commit is contained in:
parent
9692616958
commit
9268a1f59c
@ -93,21 +93,7 @@ impl RequestSet {
|
|||||||
let first_req = self.reqs.values().next()
|
let first_req = self.reqs.values().next()
|
||||||
.expect("base existing implies `reqs` non-empty; qed");
|
.expect("base existing implies `reqs` non-empty; qed");
|
||||||
|
|
||||||
// timeout is a base + value per request contained within.
|
base + compute_timeout(&first_req) <= now
|
||||||
let timeout = first_req.requests().iter().fold(timeout::BASE, |tm, req| {
|
|
||||||
tm + match *req {
|
|
||||||
Request::Headers(_) => timeout::HEADERS,
|
|
||||||
Request::HeaderProof(_) => timeout::HEADER_PROOF,
|
|
||||||
Request::Receipts(_) => timeout::RECEIPT,
|
|
||||||
Request::Body(_) => timeout::BODY,
|
|
||||||
Request::Account(_) => timeout::PROOF,
|
|
||||||
Request::Storage(_) => timeout::PROOF,
|
|
||||||
Request::Code(_) => timeout::CONTRACT_CODE,
|
|
||||||
Request::Execution(_) => timeout::TRANSACTION_PROOF,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
base + Duration::milliseconds(timeout) <= now
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collect all pending request ids.
|
/// Collect all pending request ids.
|
||||||
@ -124,25 +110,43 @@ impl RequestSet {
|
|||||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper to calculate timeout for a specific set of requests.
|
||||||
|
// it's a base amount + some amount per request.
|
||||||
|
fn compute_timeout(reqs: &Requests) -> Duration {
|
||||||
|
Duration::milliseconds(reqs.requests().iter().fold(timeout::BASE, |tm, req| {
|
||||||
|
tm + match *req {
|
||||||
|
Request::Headers(_) => timeout::HEADERS,
|
||||||
|
Request::HeaderProof(_) => timeout::HEADER_PROOF,
|
||||||
|
Request::Receipts(_) => timeout::RECEIPT,
|
||||||
|
Request::Body(_) => timeout::BODY,
|
||||||
|
Request::Account(_) => timeout::PROOF,
|
||||||
|
Request::Storage(_) => timeout::PROOF,
|
||||||
|
Request::Code(_) => timeout::CONTRACT_CODE,
|
||||||
|
Request::Execution(_) => timeout::TRANSACTION_PROOF,
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use net::{timeout, ReqId};
|
use net::ReqId;
|
||||||
use request::{Request, Receipts};
|
use request_builder::RequestBuilder;
|
||||||
use time::{SteadyTime, Duration};
|
use time::{SteadyTime, Duration};
|
||||||
use super::RequestSet;
|
use super::{RequestSet, compute_timeout};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn multi_timeout() {
|
fn multi_timeout() {
|
||||||
let test_begin = SteadyTime::now();
|
let test_begin = SteadyTime::now();
|
||||||
let mut req_set = RequestSet::default();
|
let mut req_set = RequestSet::default();
|
||||||
|
|
||||||
let the_req = Request::Receipts(Receipts { block_hashes: Vec::new() });
|
let the_req = RequestBuilder::default().build();
|
||||||
|
let req_time = compute_timeout(&the_req);
|
||||||
req_set.insert(ReqId(0), the_req.clone(), test_begin);
|
req_set.insert(ReqId(0), the_req.clone(), test_begin);
|
||||||
req_set.insert(ReqId(1), the_req, test_begin + Duration::seconds(1));
|
req_set.insert(ReqId(1), the_req, test_begin + Duration::seconds(1));
|
||||||
|
|
||||||
assert_eq!(req_set.base, Some(test_begin));
|
assert_eq!(req_set.base, Some(test_begin));
|
||||||
|
|
||||||
let test_end = test_begin + Duration::milliseconds(timeout::RECEIPTS);
|
let test_end = test_begin + req_time;
|
||||||
assert!(req_set.check_timeout(test_end));
|
assert!(req_set.check_timeout(test_end));
|
||||||
|
|
||||||
req_set.remove(&ReqId(0), test_begin + Duration::seconds(1)).unwrap();
|
req_set.remove(&ReqId(0), test_begin + Duration::seconds(1)).unwrap();
|
||||||
|
@ -349,10 +349,8 @@ mod tests {
|
|||||||
let client = TestBlockChainClient::new();
|
let client = TestBlockChainClient::new();
|
||||||
client.add_blocks(2000, EachBlockWith::Nothing);
|
client.add_blocks(2000, EachBlockWith::Nothing);
|
||||||
|
|
||||||
let req = ::request::HeaderProof {
|
let req = ::request::CompleteHeaderProofRequest {
|
||||||
cht_number: 0,
|
num: 1500,
|
||||||
block_number: 1500,
|
|
||||||
from_level: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(client.header_proof(req.clone()).is_none());
|
assert!(client.header_proof(req.clone()).is_none());
|
||||||
|
@ -346,7 +346,7 @@ impl Decodable for Kind {
|
|||||||
match rlp.as_val::<u8>()? {
|
match rlp.as_val::<u8>()? {
|
||||||
0 => Ok(Kind::Headers),
|
0 => Ok(Kind::Headers),
|
||||||
1 => Ok(Kind::HeaderProof),
|
1 => Ok(Kind::HeaderProof),
|
||||||
// 2 => Ok(Kind::TransactionIndex,
|
// 2 => Ok(Kind::TransactionIndex),
|
||||||
3 => Ok(Kind::Receipts),
|
3 => Ok(Kind::Receipts),
|
||||||
4 => Ok(Kind::Body),
|
4 => Ok(Kind::Body),
|
||||||
5 => Ok(Kind::Account),
|
5 => Ok(Kind::Account),
|
||||||
|
Loading…
Reference in New Issue
Block a user