oxedyne/fe2o3/fe2o3_o3db_sync/tests/close_chunked_put.rs
3.7 KiB, 1 run
created by r1870400018:69712, 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 chunked put accepted before a close is stored, or its caller is told it was not. The server |
| 2 | //! bot sends a chunked value's bunch key only once its chunks are readable, so the close must let |
| 3 | //! the server bots end before it finishes the readers and writers. Found by Opus QA of A3 round |
| 4 | //! 2a (M2, 2026-10-09): the caller was told `Written`, `close()` returned `Ok`, and the key was |
| 5 | //! gone after reopening. The hooks are process-wide, hence a binary of its own. |
| 6 | |
| 7 | mod gc_pair; |
| 8 | |
| 9 | use gc_pair::*; |
| 10 | |
| 11 | use oxedyne_fe2o3_core::{ |
| 12 | channels::Recv, |
| 13 | prelude::*, |
| 14 | }; |
| 15 | use oxedyne_fe2o3_iop_db::api::Database; |
| 16 | use oxedyne_fe2o3_jdat::prelude::*; |
| 17 | use oxedyne_fe2o3_o3db_sync::{ |
| 18 | base::cfg::OzoneConfig, |
| 19 | comm::msg::OzoneMsg, |
| 20 | test::{ |
| 21 | hooks, |
| 22 | setup::{ |
| 23 | self, |
| 24 | Uid, |
| 25 | }, |
| 26 | }, |
| 27 | }; |
| 28 | |
| 29 | use std::{ |
| 30 | collections::BTreeMap, |
| 31 | path::Path, |
| 32 | thread, |
| 33 | time::{ |
| 34 | Duration, |
| 35 | Instant, |
| 36 | }, |
| 37 | }; |
| 38 | |
| 39 | fn cfg(cbots: u16) -> Outcome<OzoneConfig> { |
| 40 | let mut c = res!(setup::default_cfg()); |
| 41 | c.num_zones = 1; |
| 42 | c.num_cbots_per_zone = cbots; |
| 43 | c.num_fbots_per_zone = 1; |
| 44 | c.num_wbots_per_zone = 2; |
| 45 | c.zone_overrides = BTreeMap::new(); |
| 46 | c.rest_chunk_threshold = 1_000; |
| 47 | c.rest_chunk_bytes = 400; |
| 48 | c.sync_on_write = true; |
| 49 | Ok(c) |
| 50 | } |
| 51 | |
| 52 | fn val(len: usize, seed: u8) -> Dat { |
| 53 | Dat::BU32((0..len).map(|j| seed ^ (j as u8)).collect()) |
| 54 | } |
| 55 | |
| 56 | fn start(dir: &str, c: OzoneConfig, wipe: bool) -> Outcome<TestDb> { |
| 57 | log_set_level!("error"); |
| 58 | if wipe { |
| 59 | let _ = std::fs::remove_dir_all(dir); |
| 60 | } |
| 61 | res!(std::fs::create_dir_all(dir)); |
| 62 | let root = res!(Path::new(dir).canonicalize()); |
| 63 | setup::start_db(root, Some(c), schemes(), None, false, wipe) |
| 64 | } |
| 65 | |
| 66 | #[test] |
| 67 | fn chunked_put_in_flight_at_close_is_kept() -> Outcome<()> { |
| 68 | let dir = "./test_db_close_chunked_put"; |
| 69 | let k = dat!("in flight at close"); |
| 70 | let told: Vec<String>; |
| 71 | let closed: Outcome<()>; |
| 72 | { |
| 73 | let db = res!(start(dir, res!(cfg(4)), true)); |
| 74 | res!(db.insert(key(0), value(0, 1), Uid::default(), None)); |
| 75 | hooks::set_chunk_insert_delay(Duration::from_millis(300)); |
| 76 | let resp = res!(db.api().put(k.clone(), val(1_100, 9), Uid::default(), None)); |
| 77 | thread::sleep(Duration::from_millis(20)); // the server bot has begun the put |
| 78 | closed = db.close(); |
| 79 | hooks::set_chunk_insert_delay(Duration::ZERO); |
| 80 | let chan = match resp.channel() { |
| 81 | Some(c) => c, |
| 82 | None => return Err(err!("No channel."; Test, Missing)), |
| 83 | }; |
| 84 | let mut t = Vec::new(); |
| 85 | let end = Instant::now() + Duration::from_secs(8); |
| 86 | while Instant::now() < end { |
| 87 | match chan.recv_timeout(Duration::from_millis(100)) { |
| 88 | Recv::Result(Ok(OzoneMsg::Error(e))) => t.push(fmt!("Error({})", e).chars().take(200).collect()), |
| 89 | Recv::Result(Ok(m)) => t.push(fmt!("{:?}", m).chars().take(60).collect()), |
| 90 | _ => (), |
| 91 | } |
| 92 | } |
| 93 | told = t; |
| 94 | } |
| 95 | let db = res!(start(dir, res!(cfg(4)), false)); |
| 96 | let got = res!(db.get(&k, None)); |
| 97 | res!(db.close()); |
| 98 | let _ = std::fs::remove_dir_all(dir); |
| 99 | let kept = matches!(&got, Some((v, _)) if *v == val(1_100, 9)); |
| 100 | msg!("close returned {:?}; kept {}; the caller was told {:?}", |
| 101 | closed.as_ref().map_err(|e| fmt!("{}", e)), kept, told); |
| 102 | assert!(kept, "a chunked put accepted before the close was not stored (caller told {:?})", told); |
| 103 | assert!(closed.is_ok(), "the close failed: {:?}", closed.map_err(|e| fmt!("{}", e))); |
| 104 | assert!(!told.iter().any(|m| m.starts_with("Error")), |
| 105 | "the put was stored, but its caller was told an error: {:?}", told); |
| 106 | Ok(()) |
| 107 | } |