mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-21 14:46:32 +01:00
Add test to cover state cloning in layer
This commit is contained in:
parent
092719c217
commit
296dfe1a40
1 changed files with 21 additions and 0 deletions
|
@ -3,6 +3,7 @@ use crate::{
|
|||
error_handling::HandleErrorLayer,
|
||||
extract::{self, DefaultBodyLimit, FromRef, Path, State},
|
||||
handler::{Handler, HandlerWithoutStateExt},
|
||||
middleware::{self, Next},
|
||||
response::{IntoResponse, Response},
|
||||
routing::{
|
||||
delete, get, get_service, on, on_service, patch, patch_service,
|
||||
|
@ -922,6 +923,26 @@ async fn state_isnt_cloned_too_much() {
|
|||
assert_eq!(state.count(), 3);
|
||||
}
|
||||
|
||||
#[crate::test]
|
||||
async fn state_isnt_cloned_too_much_in_layer() {
|
||||
async fn layer(State(_): State<CountingCloneableState>, req: Request, next: Next) -> Response {
|
||||
next.run(req).await
|
||||
}
|
||||
|
||||
let state = CountingCloneableState::new();
|
||||
|
||||
let app = Router::new().layer(middleware::from_fn_with_state(state.clone(), layer));
|
||||
|
||||
let client = TestClient::new(app);
|
||||
|
||||
// ignore clones made during setup
|
||||
state.setup_done();
|
||||
|
||||
client.get("/").await;
|
||||
|
||||
assert_eq!(state.count(), 4);
|
||||
}
|
||||
|
||||
#[crate::test]
|
||||
async fn logging_rejections() {
|
||||
#[derive(Deserialize, Eq, PartialEq, Debug)]
|
||||
|
|
Loading…
Reference in a new issue