diff --git a/ohkami/src/x_lambda.rs b/ohkami/src/x_lambda.rs index 321b97c1..5e34c44c 100644 --- a/ohkami/src/x_lambda.rs +++ b/ohkami/src/x_lambda.rs @@ -513,8 +513,6 @@ mod ws { #[cfg(feature="nightly"/* `noop_waker` is stabilized in 1.85.0 and then remove this cfg */)] #[cfg(test)] -/// FIXME -/// this is flaky; sometimes cause a timing conflict around `static ROUTER` (in ohkami/mod.rs, used for Service impl) mod tests { use super::*; use crate::{Ohkami, Route, Method}; @@ -557,19 +555,20 @@ mod tests { } #[test] - fn ohkami_service_call_once() { + fn ohkami_service_call() { tokio::runtime::Runtime::new().unwrap().block_on(async { - { - let mut o = Ohkami::new(( - "/hello".GET(|| async {"Hello, Service!"}), - )); - - let _ = - >>::poll_ready(&mut o, &mut Context::from_waker(Waker::noop())); - + let mut o = Ohkami::new(( + "/hello".GET(|| async {"Hello, Service!"}), + )); + + /* poll_ready first */ + let _ = + >>::poll_ready(&mut o, &mut Context::from_waker(Waker::noop())); + + {/* 404 */ let res = - >>::poll_ready(&mut o, &mut Context::from_waker(Waker::noop())); - + >>::call(&mut o, new_req( + Method::GET, + "/hello", + None + )).await.unwrap(); + + let lambda_runtime::FunctionResponse::BufferedResponse(res) = res else { + panic!("Unexpected `StreamingResponse`") + }; + + assert_eq!(res, LambdaResponse { + statusCode: 200, + headers: crate::response::ResponseHeaders::from_iter([ + ("Date", ohkami_lib::imf_fixdate(crate::util::unix_timestamp())), + ("Content-Length", "15".into()), + ("Content-Type", "text/plain; charset=UTF-8".into()), + ]), + cookies: None, + body: Some("Hello, Service!".into()), + isBase64Encoded: Some(false), + }); + } + {/* OK twice */ let res = - >>::poll_ready(&mut o, &mut Context::from_waker(Waker::noop())); - - let res = - >>::call(&mut o, new_req( - Method::GET, - "/hello", - None - )).await.unwrap(); - - let lambda_runtime::FunctionResponse::BufferedResponse(res) = res else { - panic!("Unexpected `StreamingResponse`") - }; - - assert_eq!(res, LambdaResponse { - statusCode: 200, - headers: crate::response::ResponseHeaders::from_iter([ - ("Date", ohkami_lib::imf_fixdate(crate::util::unix_timestamp())), - ("Content-Length", "15".into()), - ("Content-Type", "text/plain; charset=UTF-8".into()), - ]), - cookies: None, - body: Some("Hello, Service!".into()), - isBase64Encoded: Some(false), - }); - - let _ = - >>::call(&mut o, new_req( - Method::GET, - "/hello", - None - )); /* panics as second call */ - }); - } }