get tests compiling

This commit is contained in:
Robert Habermeier 2017-03-08 18:27:29 +01:00
parent 9692616958
commit 9268a1f59c
3 changed files with 27 additions and 25 deletions

View File

@ -93,21 +93,7 @@ impl RequestSet {
let first_req = self.reqs.values().next()
.expect("base existing implies `reqs` non-empty; qed");
// timeout is a base + value per request contained within.
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
base + compute_timeout(&first_req) <= now
}
/// Collect all pending request ids.
@ -124,25 +110,43 @@ impl RequestSet {
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)]
mod tests {
use net::{timeout, ReqId};
use request::{Request, Receipts};
use net::ReqId;
use request_builder::RequestBuilder;
use time::{SteadyTime, Duration};
use super::RequestSet;
use super::{RequestSet, compute_timeout};
#[test]
fn multi_timeout() {
let test_begin = SteadyTime::now();
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(1), the_req, test_begin + Duration::seconds(1));
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));
req_set.remove(&ReqId(0), test_begin + Duration::seconds(1)).unwrap();

View File

@ -349,10 +349,8 @@ mod tests {
let client = TestBlockChainClient::new();
client.add_blocks(2000, EachBlockWith::Nothing);
let req = ::request::HeaderProof {
cht_number: 0,
block_number: 1500,
from_level: 0,
let req = ::request::CompleteHeaderProofRequest {
num: 1500,
};
assert!(client.header_proof(req.clone()).is_none());

View File

@ -346,7 +346,7 @@ impl Decodable for Kind {
match rlp.as_val::<u8>()? {
0 => Ok(Kind::Headers),
1 => Ok(Kind::HeaderProof),
// 2 => Ok(Kind::TransactionIndex,
// 2 => Ok(Kind::TransactionIndex),
3 => Ok(Kind::Receipts),
4 => Ok(Kind::Body),
5 => Ok(Kind::Account),