Rocket/lib/benches/format-routing.rs
Sergio Benitez 1e5a1b8940 Remove 'testing' feature. Close stream on network error.
This is a breaking change.

The `testing` feature no longer exists. Testing structures can now be
accessed without any features enabled.

Prior to this change, Rocket would panic when draining from a network
stream failed. With this change, Rocket force closes the stream on any
error.

This change also ensures that the `Fairings` launch output only prints
if at least one fairing has been attached.
2017-04-20 20:36:12 -07:00

58 lines
1.6 KiB
Rust

#![feature(test, plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
use rocket::config::{Environment, Config};
use rocket::http::RawStr;
#[get("/", format = "application/json")]
fn get() -> &'static str { "get" }
#[post("/", format = "application/json")]
fn post() -> &'static str { "post" }
fn rocket() -> rocket::Rocket {
let config = Config::new(Environment::Production).unwrap();
rocket::custom(config, false)
.mount("/", routes![get, post])
}
mod benches {
extern crate test;
use super::rocket;
use self::test::Bencher;
use rocket::testing::MockRequest;
use rocket::http::Method::*;
use rocket::http::{Accept, ContentType};
#[bench]
fn accept_format(b: &mut Bencher) {
let rocket = rocket();
let mut request = MockRequest::new(Get, "/").header(Accept::JSON);
b.iter(|| { request.dispatch_with(&rocket); });
}
#[bench]
fn wrong_accept_format(b: &mut Bencher) {
let rocket = rocket();
let mut request = MockRequest::new(Get, "/").header(Accept::HTML);
b.iter(|| { request.dispatch_with(&rocket); });
}
#[bench]
fn content_type_format(b: &mut Bencher) {
let rocket = rocket();
let mut request = MockRequest::new(Post, "/").header(ContentType::JSON);
b.iter(|| { request.dispatch_with(&rocket); });
}
#[bench]
fn wrong_content_type_format(b: &mut Bencher) {
let rocket = rocket();
let mut request = MockRequest::new(Post, "/").header(ContentType::Plain);
b.iter(|| { request.dispatch_with(&rocket); });
}
}