From d2c17910670cbc704fc6ac6e16960602666905cb Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 29 Apr 2019 09:45:37 -0700 Subject: [PATCH] add async handler test with blocking call --- CHANGES.md | 1 - src/test.rs | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 3b7a30e20..84eb12dfd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,6 @@ * Add helper function for executing futures `test::block_fn()` - ### Changed * Allow to construct `Data` instances to avoid double `Arc` for `Send + Sync` types. diff --git a/src/test.rs b/src/test.rs index 2fc3e2a74..60a4a3845 100644 --- a/src/test.rs +++ b/src/test.rs @@ -640,4 +640,24 @@ mod tests { let result: Person = read_response_json(&mut app, req); assert_eq!(&result.id, "12345"); } + + #[test] + fn test_async_with_block() { + fn async_with_block() -> impl Future { + web::block(move || Some(4).ok_or("wrong")).then(|res| match res { + Ok(value) => HttpResponse::Ok() + .content_type("text/plain") + .body(format!("Async with block value: {}", value)), + Err(_) => panic!("Unexpected"), + }) + } + + let mut app = init_service( + App::new().service(web::resource("/index.html").to_async(async_with_block)), + ); + + let req = TestRequest::post().uri("/index.html").to_request(); + let res = block_on(app.call(req)).unwrap(); + assert!(res.status().is_success()); + } }