Skip to content

Commit

Permalink
tests: session expiration test
Browse files Browse the repository at this point in the history
creates a session with expiration of 1 second
and waits 1.1 seconds before checking its value
  • Loading branch information
arcstur committed May 3, 2024
1 parent 3dd9938 commit 1176cc0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,30 @@ macro_rules! route_tests {
assert_eq!(body_string(res.into_body()).await, "None");
}

#[tokio::test]
async fn expired() {
let app = $create_app(Some(Duration::seconds(1))).await;

let req = Request::builder()
.uri("/insert")
.body(Body::empty())
.unwrap();
let res = app.clone().oneshot(req).await.unwrap();
let session_cookie = get_session_cookie(res.headers()).unwrap();

// wait 1.1 seconds to be sure
tokio::time::sleep(tokio::time::Duration::from_millis(1100)).await;

let req = Request::builder()
.uri("/get_value")
.header(header::COOKIE, session_cookie.encoded().to_string())
.body(Body::empty())
.unwrap();
let res = app.oneshot(req).await.unwrap();

assert_eq!(body_string(res.into_body()).await, "None");
}

#[tokio::test]
async fn remove_last_value() {
let app = $create_app(Some(Duration::hours(1))).await;
Expand Down

0 comments on commit 1176cc0

Please sign in to comment.