2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2017-01-21 03:31:46 +00:00
|
|
|
use rocket::http::Status;
|
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
fn register_hit(client: &Client) {
|
|
|
|
let response = client.get("/").dispatch();;
|
2017-01-21 03:31:46 +00:00
|
|
|
assert_eq!(response.status(), Status::Ok);
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
fn get_count(client: &Client) -> usize {
|
|
|
|
let mut response = client.get("/count").dispatch();
|
2017-04-14 08:59:28 +00:00
|
|
|
response.body_string().and_then(|s| s.parse().ok()).unwrap()
|
2017-01-21 03:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_count() {
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(super::rocket()).unwrap();
|
2017-01-21 03:31:46 +00:00
|
|
|
|
|
|
|
// Count should start at 0.
|
2017-06-06 20:41:04 +00:00
|
|
|
assert_eq!(get_count(&client), 0);
|
2017-01-21 03:31:46 +00:00
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
for _ in 0..99 { register_hit(&client); }
|
|
|
|
assert_eq!(get_count(&client), 99);
|
2017-01-21 03:31:46 +00:00
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
register_hit(&client);
|
|
|
|
assert_eq!(get_count(&client), 100);
|
2017-01-21 03:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cargo runs each test in parallel on different threads. We use all of these
|
|
|
|
// tests below to show (and assert) that state is managed per-Rocket instance.
|
|
|
|
#[test] fn test_count_parallel() { test_count() }
|
|
|
|
#[test] fn test_count_parallel_2() { test_count() }
|
|
|
|
#[test] fn test_count_parallel_3() { test_count() }
|
|
|
|
#[test] fn test_count_parallel_4() { test_count() }
|
|
|
|
#[test] fn test_count_parallel_5() { test_count() }
|
|
|
|
#[test] fn test_count_parallel_6() { test_count() }
|
|
|
|
#[test] fn test_count_parallel_7() { test_count() }
|
|
|
|
#[test] fn test_count_parallel_8() { test_count() }
|
|
|
|
#[test] fn test_count_parallel_9() { test_count() }
|