oxedyne/fe2o3/fe2o3_o3db_sync/tests/size_bytes_vanish.rs
2.3 KiB, 1 run
created by r1870400018:67605, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! A file taken from a zone directory between its listing and its opening must not fail the size |
| 2 | //! (A3 R1, 2026-10-08). A collection renames its temporary files and deletes a wholly old file's |
| 3 | //! pair, so the listing can name a file that is gone by the time the zone bot opens it. The |
| 4 | //! listing is held by `test::hooks::set_list_delay`, which is process-wide, which is why this is a |
| 5 | //! test binary of its own with a single test. |
| 6 | |
| 7 | mod gc_pair; |
| 8 | |
| 9 | use gc_pair::*; |
| 10 | |
| 11 | use oxedyne_fe2o3_core::prelude::*; |
| 12 | use oxedyne_fe2o3_o3db_sync::test::{ |
| 13 | hooks, |
| 14 | setup, |
| 15 | }; |
| 16 | |
| 17 | use std::{ |
| 18 | path::Path, |
| 19 | thread, |
| 20 | time::Duration, |
| 21 | }; |
| 22 | |
| 23 | #[test] |
| 24 | fn main() -> Outcome<()> { |
| 25 | log_set_level!("error"); |
| 26 | let dir = "./test_db_size_bytes_vanish_walk"; |
| 27 | let _ = std::fs::remove_dir_all(dir); |
| 28 | res!(std::fs::create_dir_all(dir)); |
| 29 | let root = res!(Path::new(dir).canonicalize()); |
| 30 | |
| 31 | let probe = res!(probe("./test_db_size_bytes_vanish_walk_probe")); |
| 32 | let cfg = res!(config(5 * probe.len + probe.len / 2)); |
| 33 | let db: TestDb = res!(setup::start_db(root.clone(), Some(cfg.clone()), schemes(), None, false, true)); |
| 34 | res!(fill(&db)); |
| 35 | let before = zone_files_len(&root, &cfg); |
| 36 | |
| 37 | // A file of the kind a collection leaves while it works, and the positive control: it is in |
| 38 | // the directory, so it is in the length. |
| 39 | let decoy = zone_dir(&root, &cfg).join("decoy.tmp"); |
| 40 | res!(std::fs::write(&decoy, vec![7u8; 100])); |
| 41 | assert_eq!(res!(db.size_bytes()), before + 100, "the control file is not counted"); |
| 42 | |
| 43 | // The zone bot reads the directory, names the decoy, and waits. The decoy is taken away |
| 44 | // while it waits. |
| 45 | hooks::set_list_delay(Duration::from_millis(1500)); |
| 46 | let asker = { |
| 47 | let db = db.clone(); |
| 48 | thread::spawn(move || db.size_bytes()) |
| 49 | }; |
| 50 | thread::sleep(Duration::from_millis(400)); |
| 51 | res!(std::fs::remove_file(&decoy)); |
| 52 | let got = match asker.join() { |
| 53 | Ok(r) => res!(r), |
| 54 | Err(_) => return Err(err!("The size_bytes thread panicked."; Test, Thread)), |
| 55 | }; |
| 56 | hooks::set_list_delay(Duration::ZERO); |
| 57 | msg!("size_bytes {} with the decoy taken after it was listed, files {}.", got, before); |
| 58 | assert_eq!(got, before, "a file that vanished mid-walk changed the length"); |
| 59 | |
| 60 | res!(db.close()); |
| 61 | log_finish_wait!(); |
| 62 | let _ = std::fs::remove_dir_all(dir); |
| 63 | Ok(()) |
| 64 | } |