diff options
author | Kevin Guthrie <[email protected]> | 2024-11-18 10:43:52 -0500 |
---|---|---|
committer | Yuchen Wu <[email protected]> | 2024-12-13 17:27:40 -0800 |
commit | 9850e92e33af870a0761c2473673f9a0ada61b0b (patch) | |
tree | 9f663f0694653c2764e1dc1d0d7fce99b34fd65b /pingora-proxy/tests/test_upstream.rs | |
parent | a8a6e77eef2c0f4d2a45f00c5b0e316dd373f2f2 (diff) | |
download | pingora-9850e92e33af870a0761c2473673f9a0ada61b0b.tar.gz pingora-9850e92e33af870a0761c2473673f9a0ada61b0b.zip |
Add the ability to trigger forced-miss behavior from the `cache_hit_filter` function
Diffstat (limited to 'pingora-proxy/tests/test_upstream.rs')
-rw-r--r-- | pingora-proxy/tests/test_upstream.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pingora-proxy/tests/test_upstream.rs b/pingora-proxy/tests/test_upstream.rs index b2d9575..bbac874 100644 --- a/pingora-proxy/tests/test_upstream.rs +++ b/pingora-proxy/tests/test_upstream.rs @@ -388,6 +388,43 @@ mod test_cache { } #[tokio::test] + async fn test_force_miss() { + init(); + let url = "http://127.0.0.1:6148/unique/test_froce_miss/revalidate_now"; + + let res = reqwest::get(url).await.unwrap(); + assert_eq!(res.status(), StatusCode::OK); + let headers = res.headers(); + let cache_miss_epoch = headers["x-epoch"].to_str().unwrap().parse::<f64>().unwrap(); + assert_eq!(headers["x-cache-status"], "miss"); + assert_eq!(headers["x-upstream-status"], "200"); + assert_eq!(res.text().await.unwrap(), "hello world"); + + let res = reqwest::get(url).await.unwrap(); + assert_eq!(res.status(), StatusCode::OK); + let headers = res.headers(); + let cache_hit_epoch = headers["x-epoch"].to_str().unwrap().parse::<f64>().unwrap(); + assert_eq!(headers["x-cache-status"], "hit"); + assert!(headers.get("x-upstream-status").is_none()); + assert_eq!(res.text().await.unwrap(), "hello world"); + + assert_eq!(cache_miss_epoch, cache_hit_epoch); + + let res = reqwest::Client::new() + .get(url) + .header("x-force-miss", "1") + .send() + .await + .unwrap(); + + assert_eq!(res.status(), StatusCode::OK); + let headers = res.headers(); + assert_eq!(headers["x-cache-status"], "miss"); + assert_eq!(headers["x-upstream-status"], "200"); + assert_eq!(res.text().await.unwrap(), "hello world"); + } + + #[tokio::test] async fn test_cache_downstream_revalidation_etag() { init(); let url = "http://127.0.0.1:6148/unique/test_downstream_revalidation_etag/revalidate_now"; |