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.
This commit is contained in:
@@ -33,11 +33,11 @@ script:
|
|||||||
# Check with unstable flag
|
# Check with unstable flag
|
||||||
- cargo check --features unstable
|
- cargo check --features unstable
|
||||||
|
|
||||||
# Build the test executables
|
# Run tests, this includes lib tests and doc tests
|
||||||
- cargo build --tests --features unstable
|
- RUST_TEST_THREADS=1 cargo test
|
||||||
|
|
||||||
# Run tests
|
# Run integration tests
|
||||||
- RUST_TEST_THREADS=1 cargo test --features unstable
|
- cargo test -p h2-tests
|
||||||
|
|
||||||
# Run h2spec on stable
|
# Run h2spec on stable
|
||||||
- if [ "${TRAVIS_RUST_VERSION}" = "stable" ]; then ./ci/h2spec.sh; fi
|
- if [ "${TRAVIS_RUST_VERSION}" = "stable" ]; then ./ci/h2spec.sh; fi
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ branch = "master"
|
|||||||
unstable = []
|
unstable = []
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"tests/h2-tests",
|
||||||
|
"tests/h2-support",
|
||||||
|
"util/genfixture",
|
||||||
|
"util/genhuff",
|
||||||
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
@@ -42,7 +48,6 @@ string = "0.1"
|
|||||||
indexmap = "1.0"
|
indexmap = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio-timer = "0.1"
|
|
||||||
|
|
||||||
# Fuzzing
|
# Fuzzing
|
||||||
quickcheck = { version = "0.4.1", default-features = false }
|
quickcheck = { version = "0.4.1", default-features = false }
|
||||||
|
|||||||
15
tests/h2-support/Cargo.toml
Normal file
15
tests/h2-support/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "h2-support"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Carl Lerche <me@carllerche.com>"]
|
||||||
|
|
||||||
|
[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"
|
||||||
5
tests/h2-support/README.md
Normal file
5
tests/h2-support/README.md
Normal file
@@ -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.
|
||||||
36
tests/h2-support/src/lib.rs
Normal file
36
tests/h2-support/src/lib.rs
Normal file
@@ -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<T> = h2::Codec<T, ::std::io::Cursor<::bytes::Bytes>>;
|
||||||
|
|
||||||
|
// This is the frame type that is sent
|
||||||
|
pub type SendFrame = h2::frame::Frame<::std::io::Cursor<::bytes::Bytes>>;
|
||||||
@@ -605,11 +605,25 @@ where
|
|||||||
type Error = ();
|
type Error = ();
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
|
use self::Frame::Data;
|
||||||
|
|
||||||
let (frame, handle) = match self.inner.poll().unwrap() {
|
let (frame, handle) = match self.inner.poll().unwrap() {
|
||||||
Async::Ready((frame, handle)) => (frame, handle),
|
Async::Ready((frame, handle)) => (frame, handle),
|
||||||
Async::NotReady => return Ok(Async::NotReady),
|
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))
|
Ok(Async::Ready(handle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,19 +7,19 @@ macro_rules! raw_codec {
|
|||||||
$fn:ident => [$($chunk:expr,)+];
|
$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![];
|
let mut chunk = vec![];
|
||||||
|
|
||||||
$(
|
$(
|
||||||
$crate::support::raw::Chunk::push(&$chunk, &mut chunk);
|
$crate::raw::Chunk::push(&$chunk, &mut chunk);
|
||||||
)+
|
)+
|
||||||
|
|
||||||
b.$fn(&chunk[..]);
|
b.$fn(&chunk[..]);
|
||||||
})*
|
})*
|
||||||
|
|
||||||
$crate::support::Codec::new(b.build())
|
$crate::Codec::new(b.build())
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
11
tests/h2-tests/Cargo.toml
Normal file
11
tests/h2-tests/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "h2-tests"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Carl Lerche <me@carllerche.com>"]
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
h2-support = { path = "../h2-support" }
|
||||||
|
log = "0.4.1"
|
||||||
7
tests/h2-tests/README.md
Normal file
7
tests/h2-tests/README.md
Normal file
@@ -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.
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
extern crate h2_support;
|
||||||
|
|
||||||
pub mod support;
|
use h2_support::prelude::*;
|
||||||
use support::prelude::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn handshake() {
|
fn handshake() {
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod support;
|
extern crate h2_support;
|
||||||
use support::prelude::*;
|
|
||||||
|
use h2_support::prelude::*;
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
@@ -151,7 +152,7 @@ fn read_continuation_frames() {
|
|||||||
assert_eq!(res.status(), StatusCode::OK);
|
assert_eq!(res.status(), StatusCode::OK);
|
||||||
let (head, _body) = res.into_parts();
|
let (head, _body) = res.into_parts();
|
||||||
let expected = large.iter().fold(HeaderMap::new(), |mut map, &(name, ref value)| {
|
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.append(name, value.as_str().try_into().unwrap());
|
||||||
map
|
map
|
||||||
});
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#[macro_use]
|
extern crate h2_support;
|
||||||
pub mod support;
|
|
||||||
use support::prelude::*;
|
use h2_support::prelude::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn write_continuation_frames() {
|
fn write_continuation_frames() {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#[macro_use]
|
extern crate h2_support;
|
||||||
pub mod support;
|
|
||||||
use support::prelude::*;
|
use h2_support::prelude::*;
|
||||||
|
|
||||||
// In this case, the stream & connection both have capacity, but capacity is not
|
// In this case, the stream & connection both have capacity, but capacity is not
|
||||||
// explicitly requested.
|
// explicitly requested.
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod support;
|
extern crate h2_support;
|
||||||
use support::prelude::*;
|
|
||||||
|
use h2_support::prelude::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recv_single_ping() {
|
fn recv_single_ping() {
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod support;
|
extern crate h2_support;
|
||||||
use support::{DEFAULT_WINDOW_SIZE};
|
|
||||||
use support::prelude::*;
|
use h2_support::{DEFAULT_WINDOW_SIZE};
|
||||||
|
use h2_support::prelude::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single_stream_send_large_body() {
|
fn single_stream_send_large_body() {
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
pub mod support;
|
extern crate h2_support;
|
||||||
use support::prelude::*;
|
|
||||||
|
use h2_support::prelude::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recv_push_works() {
|
fn recv_push_works() {
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#![deny(warnings)]
|
#![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: &'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];
|
const SETTINGS_ACK: &'static [u8] = &[0, 0, 0, 4, 1, 0, 0, 0, 0];
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
extern crate h2_support;
|
||||||
|
|
||||||
pub mod support;
|
use h2_support::prelude::*;
|
||||||
use support::prelude::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn send_recv_headers_only() {
|
fn send_recv_headers_only() {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
extern crate h2_support;
|
||||||
|
|
||||||
pub mod support;
|
use h2_support::prelude::*;
|
||||||
use support::prelude::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recv_trailers_only() {
|
fn recv_trailers_only() {
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
name = "genfixture"
|
name = "genfixture"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Carl Lerche <me@carllerche.com>"]
|
authors = ["Carl Lerche <me@carllerche.com>"]
|
||||||
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
walkdir = "1.0.0"
|
walkdir = "1.0.0"
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
name = "genhuff"
|
name = "genhuff"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Carl Lerche <me@carllerche.com>"]
|
authors = ["Carl Lerche <me@carllerche.com>"]
|
||||||
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Reference in New Issue
Block a user