From 8a9dfd14dc5b24db41c3bb7085903ddb4502e914 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 3 May 2018 13:08:39 -0700 Subject: [PATCH] Move tests and support utilities to sub crates. (#268) These crates will not be published to crates.io, but moving them allows `tower-h2` to also depend on the test utilities. --- .travis.yml | 8 ++--- Cargo.toml | 7 +++- tests/h2-support/Cargo.toml | 15 ++++++++ tests/h2-support/README.md | 5 +++ tests/{support => h2-support/src}/assert.rs | 0 tests/{support => h2-support/src}/frames.rs | 0 .../{support => h2-support/src}/future_ext.rs | 0 tests/h2-support/src/lib.rs | 36 +++++++++++++++++++ tests/{support => h2-support/src}/mock.rs | 16 ++++++++- tests/{support => h2-support/src}/mock_io.rs | 0 tests/{support => h2-support/src}/mod.rs | 0 tests/{support => h2-support/src}/notify.rs | 0 tests/{support => h2-support/src}/prelude.rs | 0 tests/{support => h2-support/src}/raw.rs | 6 ++-- tests/{support => h2-support/src}/util.rs | 0 tests/h2-tests/Cargo.toml | 11 ++++++ tests/h2-tests/README.md | 7 ++++ tests/{ => h2-tests/tests}/client_request.rs | 4 +-- tests/{ => h2-tests/tests}/codec_read.rs | 7 ++-- tests/{ => h2-tests/tests}/codec_write.rs | 6 ++-- tests/{ => h2-tests/tests}/flow_control.rs | 6 ++-- tests/{ => h2-tests/tests}/ping_pong.rs | 5 +-- tests/{ => h2-tests/tests}/prioritization.rs | 7 ++-- tests/{ => h2-tests/tests}/push_promise.rs | 5 +-- tests/{ => h2-tests/tests}/server.rs | 6 ++-- tests/{ => h2-tests/tests}/stream_states.rs | 5 +-- tests/{ => h2-tests/tests}/trailers.rs | 4 +-- util/genfixture/Cargo.toml | 1 + util/genhuff/Cargo.toml | 1 + 29 files changed, 135 insertions(+), 33 deletions(-) create mode 100644 tests/h2-support/Cargo.toml create mode 100644 tests/h2-support/README.md rename tests/{support => h2-support/src}/assert.rs (100%) rename tests/{support => h2-support/src}/frames.rs (100%) rename tests/{support => h2-support/src}/future_ext.rs (100%) create mode 100644 tests/h2-support/src/lib.rs rename tests/{support => h2-support/src}/mock.rs (97%) rename tests/{support => h2-support/src}/mock_io.rs (100%) rename tests/{support => h2-support/src}/mod.rs (100%) rename tests/{support => h2-support/src}/notify.rs (100%) rename tests/{support => h2-support/src}/prelude.rs (100%) rename tests/{support => h2-support/src}/raw.rs (81%) rename tests/{support => h2-support/src}/util.rs (100%) create mode 100644 tests/h2-tests/Cargo.toml create mode 100644 tests/h2-tests/README.md rename tests/{ => h2-tests/tests}/client_request.rs (99%) rename tests/{ => h2-tests/tests}/codec_read.rs (97%) rename tests/{ => h2-tests/tests}/codec_write.rs (96%) rename tests/{ => h2-tests/tests}/flow_control.rs (99%) rename tests/{ => h2-tests/tests}/ping_pong.rs (98%) rename tests/{ => h2-tests/tests}/prioritization.rs (99%) rename tests/{ => h2-tests/tests}/push_promise.rs (99%) rename tests/{ => h2-tests/tests}/server.rs (99%) rename tests/{ => h2-tests/tests}/stream_states.rs (99%) rename tests/{ => h2-tests/tests}/trailers.rs (98%) diff --git a/.travis.yml b/.travis.yml index 02cb5b5..c42c51d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,11 +33,11 @@ script: # Check with unstable flag - cargo check --features unstable - # Build the test executables - - cargo build --tests --features unstable + # Run tests, this includes lib tests and doc tests + - RUST_TEST_THREADS=1 cargo test - # Run tests - - RUST_TEST_THREADS=1 cargo test --features unstable + # Run integration tests + - cargo test -p h2-tests # Run h2spec on stable - if [ "${TRAVIS_RUST_VERSION}" = "stable" ]; then ./ci/h2spec.sh; fi diff --git a/Cargo.toml b/Cargo.toml index 3090432..4ccfd1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,12 @@ branch = "master" unstable = [] [workspace] +members = [ + "tests/h2-tests", + "tests/h2-support", + "util/genfixture", + "util/genhuff", +] [dependencies] futures = "0.1" @@ -42,7 +48,6 @@ string = "0.1" indexmap = "1.0" [dev-dependencies] -tokio-timer = "0.1" # Fuzzing quickcheck = { version = "0.4.1", default-features = false } diff --git a/tests/h2-support/Cargo.toml b/tests/h2-support/Cargo.toml new file mode 100644 index 0000000..fb46928 --- /dev/null +++ b/tests/h2-support/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "h2-support" +version = "0.1.0" +authors = ["Carl Lerche "] + +[dependencies] +h2 = { path = "../..", features = ["unstable"] } + +bytes = "0.4.7" +env_logger = "0.5.9" +futures = "0.1.21" +http = "0.1.5" +string = "0.1.0" +tokio-io = "0.1.6" +tokio-timer = "0.1.2" diff --git a/tests/h2-support/README.md b/tests/h2-support/README.md new file mode 100644 index 0000000..ffc0d22 --- /dev/null +++ b/tests/h2-support/README.md @@ -0,0 +1,5 @@ +# h2 test support + +This crate includes utilities for writing h2 tests. This is broken up into a +separate crate because it requires the `unstable` feature flag and to enable +`tower-h2` to use the same helpers. diff --git a/tests/support/assert.rs b/tests/h2-support/src/assert.rs similarity index 100% rename from tests/support/assert.rs rename to tests/h2-support/src/assert.rs diff --git a/tests/support/frames.rs b/tests/h2-support/src/frames.rs similarity index 100% rename from tests/support/frames.rs rename to tests/h2-support/src/frames.rs diff --git a/tests/support/future_ext.rs b/tests/h2-support/src/future_ext.rs similarity index 100% rename from tests/support/future_ext.rs rename to tests/h2-support/src/future_ext.rs diff --git a/tests/h2-support/src/lib.rs b/tests/h2-support/src/lib.rs new file mode 100644 index 0000000..036637f --- /dev/null +++ b/tests/h2-support/src/lib.rs @@ -0,0 +1,36 @@ +//! Utilities to support tests. + +pub extern crate bytes; +pub extern crate env_logger; +#[macro_use] +pub extern crate futures; +pub extern crate h2; +pub extern crate http; +pub extern crate string; +#[macro_use] +pub extern crate tokio_io; + +#[macro_use] +mod assert; + +pub mod raw; + +pub mod frames; +pub mod prelude; +pub mod mock; +pub mod mock_io; +pub mod notify; +pub mod util; + +mod future_ext; + +pub use future_ext::{FutureExt, Unwrap}; + +pub type WindowSize = usize; +pub const DEFAULT_WINDOW_SIZE: WindowSize = (1 << 16) - 1; + +// This is our test Codec type +pub type Codec = h2::Codec>; + +// This is the frame type that is sent +pub type SendFrame = h2::frame::Frame<::std::io::Cursor<::bytes::Bytes>>; diff --git a/tests/support/mock.rs b/tests/h2-support/src/mock.rs similarity index 97% rename from tests/support/mock.rs rename to tests/h2-support/src/mock.rs index 761bd75..1f0e98b 100644 --- a/tests/support/mock.rs +++ b/tests/h2-support/src/mock.rs @@ -605,11 +605,25 @@ where type Error = (); fn poll(&mut self) -> Poll { + use self::Frame::Data; + let (frame, handle) = match self.inner.poll().unwrap() { Async::Ready((frame, handle)) => (frame, handle), Async::NotReady => return Ok(Async::NotReady), }; - assert_eq!(frame.unwrap(), self.frame, "recv_frame"); + + let frame = frame.unwrap(); + + match (frame, &self.frame) { + (Data(ref a), &Data(ref b)) => { + assert_eq!(a.payload().len(), b.payload().len(), "recv_frame data payload len"); + assert_eq!(a, b, "recv_frame"); + } + (ref a, b) => { + assert_eq!(a, b, "recv_frame"); + } + } + Ok(Async::Ready(handle)) } } diff --git a/tests/support/mock_io.rs b/tests/h2-support/src/mock_io.rs similarity index 100% rename from tests/support/mock_io.rs rename to tests/h2-support/src/mock_io.rs diff --git a/tests/support/mod.rs b/tests/h2-support/src/mod.rs similarity index 100% rename from tests/support/mod.rs rename to tests/h2-support/src/mod.rs diff --git a/tests/support/notify.rs b/tests/h2-support/src/notify.rs similarity index 100% rename from tests/support/notify.rs rename to tests/h2-support/src/notify.rs diff --git a/tests/support/prelude.rs b/tests/h2-support/src/prelude.rs similarity index 100% rename from tests/support/prelude.rs rename to tests/h2-support/src/prelude.rs diff --git a/tests/support/raw.rs b/tests/h2-support/src/raw.rs similarity index 81% rename from tests/support/raw.rs rename to tests/h2-support/src/raw.rs index 31dece6..fbaa109 100644 --- a/tests/support/raw.rs +++ b/tests/h2-support/src/raw.rs @@ -7,19 +7,19 @@ macro_rules! raw_codec { $fn:ident => [$($chunk:expr,)+]; )* ) => {{ - let mut b = $crate::support::mock_io::Builder::new(); + let mut b = $crate::mock_io::Builder::new(); $({ let mut chunk = vec![]; $( - $crate::support::raw::Chunk::push(&$chunk, &mut chunk); + $crate::raw::Chunk::push(&$chunk, &mut chunk); )+ b.$fn(&chunk[..]); })* - $crate::support::Codec::new(b.build()) + $crate::Codec::new(b.build()) }} } diff --git a/tests/support/util.rs b/tests/h2-support/src/util.rs similarity index 100% rename from tests/support/util.rs rename to tests/h2-support/src/util.rs diff --git a/tests/h2-tests/Cargo.toml b/tests/h2-tests/Cargo.toml new file mode 100644 index 0000000..41642e7 --- /dev/null +++ b/tests/h2-tests/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "h2-tests" +version = "0.1.0" +authors = ["Carl Lerche "] +publish = false + +[dependencies] + +[dev-dependencies] +h2-support = { path = "../h2-support" } +log = "0.4.1" diff --git a/tests/h2-tests/README.md b/tests/h2-tests/README.md new file mode 100644 index 0000000..d044708 --- /dev/null +++ b/tests/h2-tests/README.md @@ -0,0 +1,7 @@ +# h2 integration tests + +This crate includes the h2 integration tests. These tests exist in a separate +crate because they transitively depend on the `unstable` feature flag via +`h2-support`. Due to a cargo limitation, if these tests existed as part of the +`h2` crate, it would require that `h2-support` be published to crates.io and +force the `unstable` feature flag to always be on. diff --git a/tests/client_request.rs b/tests/h2-tests/tests/client_request.rs similarity index 99% rename from tests/client_request.rs rename to tests/h2-tests/tests/client_request.rs index 433faa3..e3bca1f 100644 --- a/tests/client_request.rs +++ b/tests/h2-tests/tests/client_request.rs @@ -1,8 +1,8 @@ #[macro_use] extern crate log; +extern crate h2_support; -pub mod support; -use support::prelude::*; +use h2_support::prelude::*; #[test] fn handshake() { diff --git a/tests/codec_read.rs b/tests/h2-tests/tests/codec_read.rs similarity index 97% rename from tests/codec_read.rs rename to tests/h2-tests/tests/codec_read.rs index 1c2658e..ff97c30 100644 --- a/tests/codec_read.rs +++ b/tests/h2-tests/tests/codec_read.rs @@ -1,6 +1,7 @@ #[macro_use] -pub mod support; -use support::prelude::*; +extern crate h2_support; + +use h2_support::prelude::*; use std::error::Error; @@ -151,7 +152,7 @@ fn read_continuation_frames() { assert_eq!(res.status(), StatusCode::OK); let (head, _body) = res.into_parts(); let expected = large.iter().fold(HeaderMap::new(), |mut map, &(name, ref value)| { - use support::frames::HttpTryInto; + use h2_support::frames::HttpTryInto; map.append(name, value.as_str().try_into().unwrap()); map }); diff --git a/tests/codec_write.rs b/tests/h2-tests/tests/codec_write.rs similarity index 96% rename from tests/codec_write.rs rename to tests/h2-tests/tests/codec_write.rs index 71e7807..f34d391 100644 --- a/tests/codec_write.rs +++ b/tests/h2-tests/tests/codec_write.rs @@ -1,6 +1,6 @@ -#[macro_use] -pub mod support; -use support::prelude::*; +extern crate h2_support; + +use h2_support::prelude::*; #[test] fn write_continuation_frames() { diff --git a/tests/flow_control.rs b/tests/h2-tests/tests/flow_control.rs similarity index 99% rename from tests/flow_control.rs rename to tests/h2-tests/tests/flow_control.rs index 178f37f..1cd8038 100644 --- a/tests/flow_control.rs +++ b/tests/h2-tests/tests/flow_control.rs @@ -1,6 +1,6 @@ -#[macro_use] -pub mod support; -use support::prelude::*; +extern crate h2_support; + +use h2_support::prelude::*; // In this case, the stream & connection both have capacity, but capacity is not // explicitly requested. diff --git a/tests/ping_pong.rs b/tests/h2-tests/tests/ping_pong.rs similarity index 98% rename from tests/ping_pong.rs rename to tests/h2-tests/tests/ping_pong.rs index d77a869..b726790 100644 --- a/tests/ping_pong.rs +++ b/tests/h2-tests/tests/ping_pong.rs @@ -1,6 +1,7 @@ #[macro_use] -pub mod support; -use support::prelude::*; +extern crate h2_support; + +use h2_support::prelude::*; #[test] fn recv_single_ping() { diff --git a/tests/prioritization.rs b/tests/h2-tests/tests/prioritization.rs similarity index 99% rename from tests/prioritization.rs rename to tests/h2-tests/tests/prioritization.rs index e9c7a4c..e475ab3 100644 --- a/tests/prioritization.rs +++ b/tests/h2-tests/tests/prioritization.rs @@ -1,7 +1,8 @@ #[macro_use] -pub mod support; -use support::{DEFAULT_WINDOW_SIZE}; -use support::prelude::*; +extern crate h2_support; + +use h2_support::{DEFAULT_WINDOW_SIZE}; +use h2_support::prelude::*; #[test] fn single_stream_send_large_body() { diff --git a/tests/push_promise.rs b/tests/h2-tests/tests/push_promise.rs similarity index 99% rename from tests/push_promise.rs rename to tests/h2-tests/tests/push_promise.rs index 6f4561c..cc32d82 100644 --- a/tests/push_promise.rs +++ b/tests/h2-tests/tests/push_promise.rs @@ -1,5 +1,6 @@ -pub mod support; -use support::prelude::*; +extern crate h2_support; + +use h2_support::prelude::*; #[test] fn recv_push_works() { diff --git a/tests/server.rs b/tests/h2-tests/tests/server.rs similarity index 99% rename from tests/server.rs rename to tests/h2-tests/tests/server.rs index c180715..5007150 100644 --- a/tests/server.rs +++ b/tests/h2-tests/tests/server.rs @@ -1,6 +1,8 @@ #![deny(warnings)] -pub mod support; -use support::prelude::*; + +extern crate h2_support; + +use h2_support::prelude::*; const SETTINGS: &'static [u8] = &[0, 0, 0, 4, 0, 0, 0, 0, 0]; const SETTINGS_ACK: &'static [u8] = &[0, 0, 0, 4, 1, 0, 0, 0, 0]; diff --git a/tests/stream_states.rs b/tests/h2-tests/tests/stream_states.rs similarity index 99% rename from tests/stream_states.rs rename to tests/h2-tests/tests/stream_states.rs index c48d66c..4cce496 100644 --- a/tests/stream_states.rs +++ b/tests/h2-tests/tests/stream_states.rs @@ -1,9 +1,10 @@ #![deny(warnings)] + #[macro_use] extern crate log; +extern crate h2_support; -pub mod support; -use support::prelude::*; +use h2_support::prelude::*; #[test] fn send_recv_headers_only() { diff --git a/tests/trailers.rs b/tests/h2-tests/tests/trailers.rs similarity index 98% rename from tests/trailers.rs rename to tests/h2-tests/tests/trailers.rs index 4953e48..f44f72b 100644 --- a/tests/trailers.rs +++ b/tests/h2-tests/tests/trailers.rs @@ -1,8 +1,8 @@ #[macro_use] extern crate log; +extern crate h2_support; -pub mod support; -use support::prelude::*; +use h2_support::prelude::*; #[test] fn recv_trailers_only() { diff --git a/util/genfixture/Cargo.toml b/util/genfixture/Cargo.toml index cbb8fe9..fdbb6e6 100644 --- a/util/genfixture/Cargo.toml +++ b/util/genfixture/Cargo.toml @@ -2,6 +2,7 @@ name = "genfixture" version = "0.1.0" authors = ["Carl Lerche "] +publish = false [dependencies] walkdir = "1.0.0" diff --git a/util/genhuff/Cargo.toml b/util/genhuff/Cargo.toml index 59887ed..1d40f6b 100644 --- a/util/genhuff/Cargo.toml +++ b/util/genhuff/Cargo.toml @@ -2,5 +2,6 @@ name = "genhuff" version = "0.1.0" authors = ["Carl Lerche "] +publish = false [dependencies]