MCPcopy Create free account
hub / github.com/chatmail/core / test_http_cache

Function test_http_cache

src/net/http.rs:497–606  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

495
496 #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
497 async fn test_http_cache() -> Result<()> {
498 let t = &TestContext::new().await;
499
500 assert_eq!(http_cache_get(t, "https://webxdc.org/").await?, None);
501
502 let html_response = Response {
503 blob: b"<!DOCTYPE html> ...".to_vec(),
504 mimetype: Some("text/html".to_string()),
505 encoding: None,
506 };
507
508 let xdc_response = Response {
509 blob: b"PK...".to_vec(),
510 mimetype: Some("application/octet-stream".to_string()),
511 encoding: None,
512 };
513 let xdc_editor_url = "https://apps.testrun.org/webxdc-editor-v3.2.0.xdc";
514 let xdc_pixel_url = "https://apps.testrun.org/webxdc-pixel-v2.xdc";
515
516 http_cache_put(t, "https://webxdc.org/", &html_response).await?;
517
518 assert_eq!(http_cache_get(t, xdc_editor_url).await?, None);
519 assert_eq!(http_cache_get(t, xdc_pixel_url).await?, None);
520 assert_eq!(
521 http_cache_get(t, "https://webxdc.org/").await?,
522 Some((html_response.clone(), false))
523 );
524
525 http_cache_put(t, xdc_editor_url, &xdc_response).await?;
526 http_cache_put(t, xdc_pixel_url, &xdc_response).await?;
527 assert_eq!(
528 http_cache_get(t, xdc_editor_url).await?,
529 Some((xdc_response.clone(), false))
530 );
531 assert_eq!(
532 http_cache_get(t, xdc_pixel_url).await?,
533 Some((xdc_response.clone(), false))
534 );
535
536 assert_eq!(
537 http_cache_get(t, "https://webxdc.org/").await?,
538 Some((html_response.clone(), false))
539 );
540
541 // HTML is stale after 1 hour, but .xdc is not.
542 SystemTime::shift(Duration::from_secs(3600 + 100));
543 assert_eq!(
544 http_cache_get(t, "https://webxdc.org/").await?,
545 Some((html_response.clone(), true))
546 );
547 assert_eq!(
548 http_cache_get(t, xdc_editor_url).await?,
549 Some((xdc_response.clone(), false))
550 );
551
552 // Stale cache entry can be renewed
553 // even before housekeeping removes old one.
554 http_cache_put(t, "https://webxdc.org/", &html_response).await?;

Callers

nothing calls this directly

Calls 5

http_cache_putFunction · 0.85
housekeepingFunction · 0.85
http_cache_getFunction · 0.85
read_dirFunction · 0.85
get_blobdirMethod · 0.45

Tested by

no test coverage detected