()
| 605 | let db_path = cache_dir.path().join("cache.redb"); |
| 606 | let key = "GET:http://example.com/corrupt"; |
| 607 | |
| 608 | // Initialize the database + table via the manager, then drop it to |
| 609 | // release redb's exclusive file lock. |
| 610 | drop(RedbManager::new(&db_path)?); |
| 611 | |
| 612 | // Write undecodable bytes for the key directly into the same table the |
| 613 | // manager reads from. |
| 614 | { |
| 615 | let db = Database::create(&db_path)?; |
| 616 | let write_txn = db.begin_write()?; |
| 617 | { |
| 618 | let mut table = |
| 619 | write_txn.open_table(crate::managers::redb::TABLE)?; |
| 620 | table.insert(key, b"not valid postcard data".as_slice())?; |
| 621 | } |
| 622 | write_txn.commit()?; |
| 623 | } |
| 624 | |
| 625 | let manager = RedbManager::new(&db_path)?; |
| 626 | let result = manager.get(key).await?; |
| 627 | assert!(result.is_none()); |
| 628 | Ok(()) |
| 629 | } |
| 630 | |
| 631 | // The manager needs no tokio reactor: drive it on a non-tokio executor |
| 632 | // (smol, as used by http-cache-ureq / Bevy) with no tokio runtime present. |
| 633 | #[test] |
| 634 | fn redb_works_without_tokio_runtime() -> Result<()> { |
| 635 | smol::block_on(async { |
| 636 | let url = url_parse("http://example.com/smol")?; |
| 637 | let cache_dir = tempfile::tempdir().unwrap(); |
| 638 | let manager = |
| 639 | RedbManager::new(cache_dir.path().join("cache.redb"))?; |
| 640 | let key = format!("{}:{}", GET, url); |
| 641 | let req = http::Request::get("http://example.com/smol").body(())?; |
| 642 | let res = http::Response::builder() |
| 643 | .status(200) |
| 644 | .body(TEST_BODY.to_vec())?; |
nothing calls this directly
no test coverage detected