Files
valeriansaliou-sonic/core/tests/data_backup.rs
T
dualfroz 73692bcfdb fix(core): Back up and restore FST buckets again
Since 27a1b2b ("chore(core): Flatten FST store code"), the bucket loop in
`FstStorePool::dump_action` checked the type and name of the collection
entry instead of the bucket entry. As a collection is a directory, every
bucket was skipped: `TRIGGER backup` answered `OK` but wrote no FST, and
`TRIGGER restore` restored none.

Add a test which backs up a consolidated FST and restores it.
2026-10-03 17:33:05 +02:00

47 lines
1.4 KiB
Rust

// Sonic
//
// Fast, lightweight and schema-less search backend
// Copyright: 2026, DualFroz <me@dualfroz.com>
// License: Mozilla Public License v2.0 (MPL v2.0)
//! Feature: Data backup
mod common;
use crate::common::util::unique_hex;
use crate::common::*;
/// Consolidated FST stores are backed up, and can be restored.
#[test]
fn test_fst_backup_and_restore() {
init_logging();
let executor = make_test_executor(|_| {});
exec!(executor -> PUSH "messages" "user:1" "chat:1" "Hello world");
exec!(executor -> TRIGGER consolidate);
let backup_path = std::path::Path::new(env!("CARGO_TARGET_TMPDIR"))
.join(unique_hex().unwrap())
.join("fst-backup");
executor.fst_pool.backup(&backup_path).unwrap();
let backup_files = std::fs::read_dir(&backup_path)
.unwrap()
.flat_map(|collection| std::fs::read_dir(collection.unwrap().path()).unwrap())
.map(|bucket| bucket.unwrap().path())
.collect::<Vec<_>>();
assert_eq!(backup_files.len(), 1, "got: {backup_files:?}");
assert!(
backup_files[0].to_string_lossy().ends_with(".fst.bck"),
"got: {backup_files:?}"
);
let restored_executor = make_test_executor(|_| {});
restored_executor.fst_pool.restore(&backup_path).unwrap();
let response = exec!(restored_executor -> LIST "messages" "user:1");
assert_contains!(response, ["hello", "world"]);
}