fetch: replace futures-timer with tokio-timer (#9066)
* fetch: replace futures-timer with tokio-timer Currently the coverage build fails because `futures-timer` fails to compile with `-C link-dead-code`. This issue has been reported to `futures-timer` (https://github.com/alexcrichton/futures-timer/issues/2) but has remained unsolved for months. It should be fixed by rustc eventually (https://github.com/rust-lang/rust/issues/45629). * ci: only include local paths in coverage * ci: exclude target from coverage
This commit is contained in:
parent
8d171a37f8
commit
ca6edcaf71
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -1112,11 +1112,11 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.11.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper-rustls 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -1189,14 +1189,6 @@ dependencies = [
|
||||
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-timer"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gcc"
|
||||
version = "0.3.54"
|
||||
@ -3978,7 +3970,6 @@ dependencies = [
|
||||
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||
"checksum futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "1a70b146671de62ec8c8ed572219ca5d594d9b06c0b364d5e67b722fc559b48c"
|
||||
"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4"
|
||||
"checksum futures-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a5cedfe9b6dc756220782cc1ba5bcb1fa091cdcba155e40d3556159c3db58043"
|
||||
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
|
||||
"checksum getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "65922871abd2f101a2eb0eaebadc66668e54a87ad9c3dd82520b5f86ede5eff9"
|
||||
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
|
||||
|
@ -15,18 +15,17 @@ set -x
|
||||
RUSTFLAGS="-C link-dead-code" cargo test --all --no-run || exit $?
|
||||
KCOV_TARGET="target/cov"
|
||||
KCOV_FLAGS="--verify"
|
||||
EXCLUDE="/usr/lib,/usr/include,$HOME/.cargo,$HOME/.multirust,rocksdb,secp256k1"
|
||||
mkdir -p $KCOV_TARGET
|
||||
echo "Cover RUST"
|
||||
for FILE in `find target/debug/deps ! -name "*.*"`
|
||||
do
|
||||
timeout --signal=SIGKILL 5m kcov --exclude-pattern $EXCLUDE $KCOV_FLAGS $KCOV_TARGET $FILE
|
||||
done
|
||||
timeout --signal=SIGKILL 5m kcov --exclude-pattern $EXCLUDE $KCOV_FLAGS $KCOV_TARGET target/debug/parity-*
|
||||
do
|
||||
timeout --signal=SIGKILL 5m kcov --include-path=$(pwd) --exclude-path=$(pwd)/target $KCOV_FLAGS $KCOV_TARGET $FILE
|
||||
done
|
||||
timeout --signal=SIGKILL 5m kcov --include-path=$(pwd) --exclude-path=$(pwd)/target $KCOV_FLAGS $KCOV_TARGET target/debug/parity-*
|
||||
echo "Cover JS"
|
||||
cd js
|
||||
npm install&&npm run test:coverage
|
||||
cd ..
|
||||
bash <(curl -s https://codecov.io/bash)&&
|
||||
echo "Uploaded code coverage"
|
||||
echo "Uploaded code coverage"
|
||||
exit 0
|
||||
|
@ -8,11 +8,11 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
futures = "0.1"
|
||||
futures-timer = "0.1"
|
||||
hyper = "0.11"
|
||||
hyper-rustls = "0.11"
|
||||
log = "0.4"
|
||||
tokio-core = "0.1"
|
||||
tokio-timer = "0.1"
|
||||
url = "1"
|
||||
bytes = "0.4"
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
use futures::future::{self, Loop};
|
||||
use futures::sync::{mpsc, oneshot};
|
||||
use futures::{self, Future, Async, Sink, Stream};
|
||||
use futures_timer::FutureExt;
|
||||
use hyper::header::{UserAgent, Location, ContentLength, ContentType};
|
||||
use hyper::mime::Mime;
|
||||
use hyper::{self, Method, StatusCode};
|
||||
@ -31,6 +30,7 @@ use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::{io, fmt};
|
||||
use tokio_core::reactor;
|
||||
use tokio_timer::{self, Timer};
|
||||
use url::{self, Url};
|
||||
use bytes::Bytes;
|
||||
|
||||
@ -142,6 +142,7 @@ type ChanItem = Option<(Request, Abort, TxResponse)>;
|
||||
pub struct Client {
|
||||
core: mpsc::Sender<ChanItem>,
|
||||
refs: Arc<AtomicUsize>,
|
||||
timer: Timer,
|
||||
}
|
||||
|
||||
// When cloning a client we increment the internal reference counter.
|
||||
@ -151,6 +152,7 @@ impl Clone for Client {
|
||||
Client {
|
||||
core: self.core.clone(),
|
||||
refs: self.refs.clone(),
|
||||
timer: self.timer.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -193,6 +195,7 @@ impl Client {
|
||||
Ok(Client {
|
||||
core: tx_proto,
|
||||
refs: Arc::new(AtomicUsize::new(1)),
|
||||
timer: Timer::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -286,17 +289,9 @@ impl Fetch for Client {
|
||||
Error::BackgroundThreadDead
|
||||
})
|
||||
.and_then(|_| rx_res.map_err(|oneshot::Canceled| Error::BackgroundThreadDead))
|
||||
.and_then(future::result)
|
||||
.timeout(maxdur)
|
||||
.map_err(|err| {
|
||||
if let Error::Io(ref e) = err {
|
||||
if let io::ErrorKind::TimedOut = e.kind() {
|
||||
return Error::Timeout
|
||||
}
|
||||
}
|
||||
err.into()
|
||||
});
|
||||
Box::new(future)
|
||||
.and_then(future::result);
|
||||
|
||||
Box::new(self.timer.timeout(future, maxdur))
|
||||
}
|
||||
|
||||
/// Get content from some URL.
|
||||
@ -575,6 +570,8 @@ pub enum Error {
|
||||
Aborted,
|
||||
/// Too many redirects have been encountered.
|
||||
TooManyRedirects,
|
||||
/// tokio-timer gave us an error.
|
||||
Timer(tokio_timer::TimerError),
|
||||
/// The maximum duration was reached.
|
||||
Timeout,
|
||||
/// The response body is too large.
|
||||
@ -592,6 +589,7 @@ impl fmt::Display for Error {
|
||||
Error::Io(ref e) => write!(fmt, "{}", e),
|
||||
Error::BackgroundThreadDead => write!(fmt, "background thread gond"),
|
||||
Error::TooManyRedirects => write!(fmt, "too many redirects"),
|
||||
Error::Timer(ref e) => write!(fmt, "{}", e),
|
||||
Error::Timeout => write!(fmt, "request timed out"),
|
||||
Error::SizeLimit => write!(fmt, "size limit reached"),
|
||||
}
|
||||
@ -616,14 +614,23 @@ impl From<url::ParseError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> From<tokio_timer::TimeoutError<F>> for Error {
|
||||
fn from(e: tokio_timer::TimeoutError<F>) -> Self {
|
||||
match e {
|
||||
tokio_timer::TimeoutError::Timer(_, e) => Error::Timer(e),
|
||||
tokio_timer::TimeoutError::TimedOut(_) => Error::Timeout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use futures::future;
|
||||
use futures::sync::mpsc;
|
||||
use futures_timer::Delay;
|
||||
use hyper::StatusCode;
|
||||
use hyper::server::{Http, Request, Response, Service};
|
||||
use tokio_timer::Timer;
|
||||
use std;
|
||||
use std::io::Read;
|
||||
use std::net::SocketAddr;
|
||||
@ -720,7 +727,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
struct TestServer;
|
||||
struct TestServer(Timer);
|
||||
|
||||
impl Service for TestServer {
|
||||
type Request = Request;
|
||||
@ -750,7 +757,10 @@ mod test {
|
||||
}
|
||||
"/delay" => {
|
||||
let d = Duration::from_secs(req.uri().query().unwrap_or("0").parse().unwrap());
|
||||
Box::new(Delay::new(d).from_err().map(|_| Response::new()))
|
||||
Box::new(self.0.sleep(d)
|
||||
.map_err(|_| return io::Error::new(io::ErrorKind::Other, "timer error"))
|
||||
.from_err()
|
||||
.map(|_| Response::new()))
|
||||
}
|
||||
_ => Box::new(future::ok(Response::new().with_status(StatusCode::NotFound)))
|
||||
}
|
||||
@ -764,7 +774,7 @@ mod test {
|
||||
let rx_end_fut = rx_end.into_future().map(|_| ()).map_err(|_| ());
|
||||
thread::spawn(move || {
|
||||
let addr = ADDRESS.parse().unwrap();
|
||||
let server = Http::new().bind(&addr, || Ok(TestServer)).unwrap();
|
||||
let server = Http::new().bind(&addr, || Ok(TestServer(Timer::default()))).unwrap();
|
||||
tx_start.send(server.local_addr().unwrap()).unwrap_or(());
|
||||
server.run_until(rx_end_fut).unwrap();
|
||||
});
|
||||
|
@ -23,12 +23,12 @@ extern crate log;
|
||||
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
extern crate futures_timer;
|
||||
|
||||
extern crate hyper;
|
||||
extern crate hyper_rustls;
|
||||
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_timer;
|
||||
extern crate url;
|
||||
extern crate bytes;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user