mirror of
https://github.com/qdrant/qdrant.git
synced 2026-08-06 10:00:58 -05:00
* build(deps): bump rand_distr from 0.5.1 to 0.6.0 Bumps [rand_distr](https://github.com/rust-random/rand_distr) from 0.5.1 to 0.6.0. - [Release notes](https://github.com/rust-random/rand_distr/releases) - [Changelog](https://github.com/rust-random/rand_distr/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-random/rand_distr/compare/0.5.1...0.6.0) --- updated-dependencies: - dependency-name: rand_distr dependency-version: 0.6.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Migrate main code base to rand 0.10 * Migrate tests * Migrate benches --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: timvisee <tim@visee.me>
70 lines
2.2 KiB
Rust
70 lines
2.2 KiB
Rust
//! Simulates a process crash while writing to a write ahead log segment.
|
|
//!
|
|
//! Steps:
|
|
//!
|
|
//! 1. The test process creates a seed and a temporary directory
|
|
//! 2. The test process creates a subprocess with the seed and directory as
|
|
//! arguments.
|
|
//! 3. The subprocess creates a segment in the directory, and appends entries to
|
|
//! the segment based on the seed.
|
|
//! 4. The subprocess aborts without closing resources or cleaning up state.
|
|
//! 5. The test process reads the entries from the segment, ensuring that no
|
|
//! corruption or data loss has occurred.
|
|
|
|
use std::collections::HashMap;
|
|
use std::{env, process};
|
|
|
|
use rand::Rng;
|
|
use tempfile::Builder;
|
|
use wal::test_utils::EntryGenerator;
|
|
|
|
const SEGMENT_CAPACITY: usize = 32 * 1024 * 1024;
|
|
const EXIT_CODE: i32 = 42;
|
|
|
|
#[test]
|
|
fn process_crash() {
|
|
let vars: HashMap<String, String> = env::vars().collect();
|
|
if vars.contains_key("SEED") && vars.contains_key("SEGMENT_PATH") {
|
|
let seed: usize = vars["SEED"].parse().unwrap();
|
|
let path = vars["SEGMENT_PATH"].clone();
|
|
subprocess(path, seed);
|
|
} else {
|
|
test()
|
|
}
|
|
}
|
|
|
|
fn test() {
|
|
let tempdir = Builder::new().prefix("segment").tempdir().unwrap();
|
|
let seed: usize = rand::rng().next_u32() as usize;
|
|
let path = tempdir.path().join("segment");
|
|
|
|
println!("Spawning subprocess; path: {path:?}; seed: {seed}");
|
|
|
|
let exit_code = process::Command::new(env::current_exe().unwrap())
|
|
.env("SEED", format!("{seed}"))
|
|
.env("SEGMENT_PATH", format!("{}", path.display()))
|
|
.status()
|
|
.unwrap()
|
|
.code()
|
|
.unwrap();
|
|
|
|
assert_eq!(EXIT_CODE, exit_code);
|
|
|
|
let segment = wal::Segment::open(path).unwrap();
|
|
let entries = EntryGenerator::with_seed_and_segment_capacity(seed, SEGMENT_CAPACITY);
|
|
|
|
for (i, entry) in entries.into_iter().enumerate() {
|
|
assert_eq!(&entry[..], &*segment.entry(i).unwrap());
|
|
}
|
|
}
|
|
|
|
fn subprocess(path: String, seed: usize) {
|
|
let mut segment = wal::Segment::create(path, SEGMENT_CAPACITY).unwrap();
|
|
|
|
for entry in EntryGenerator::with_seed_and_segment_capacity(seed, SEGMENT_CAPACITY) {
|
|
segment.append(&entry).expect("segment capacity exhausted");
|
|
}
|
|
|
|
process::exit(EXIT_CODE);
|
|
}
|