MeiliSearch/meilisearch-http/tests/snapshot/mod.rs

81 lines
2.4 KiB
Rust
Raw Normal View History

2021-03-25 10:24:33 +01:00
use std::time::Duration;
2022-10-20 18:00:07 +02:00
use meilisearch_http::Opt;
2021-03-25 10:24:33 +01:00
use tokio::time::sleep;
2022-10-20 18:00:07 +02:00
use crate::common::server::default_settings;
use crate::common::{GetAllDocumentsOptions, Server};
2021-03-25 10:24:33 +01:00
macro_rules! verify_snapshot {
(
$orig:expr,
$snapshot: expr,
|$server:ident| =>
$($e:expr,)+) => {
use std::sync::Arc;
let snapshot = Arc::new($snapshot);
let orig = Arc::new($orig);
$(
{
let test= |$server: Arc<Server>| async move {
$e.await
};
let (snapshot, _) = test(snapshot.clone()).await;
let (orig, _) = test(orig.clone()).await;
assert_eq!(snapshot, orig);
}
)*
};
}
2021-03-25 10:24:33 +01:00
#[actix_rt::test]
2022-10-22 16:07:29 +02:00
#[ignore] // TODO: unignore
2021-03-25 10:24:33 +01:00
async fn perform_snapshot() {
2021-09-28 18:10:09 +02:00
let temp = tempfile::tempdir().unwrap();
let snapshot_dir = tempfile::tempdir().unwrap();
2021-03-25 10:24:33 +01:00
let options = Opt {
snapshot_dir: snapshot_dir.path().to_owned(),
snapshot_interval_sec: 1,
schedule_snapshot: true,
..default_settings(temp.path())
};
2022-04-28 10:48:57 +02:00
let server = Server::new_with_options(options).await.unwrap();
2021-03-25 10:24:33 +01:00
let index = server.index("test");
index
.update_settings(serde_json::json! ({
"searchableAttributes": [],
}))
.await;
2021-03-25 10:24:33 +01:00
index.load_test_set().await;
server.index("test1").create(Some("prim")).await;
index.wait_task(2).await;
2021-03-25 10:24:33 +01:00
sleep(Duration::from_secs(2)).await;
2021-09-28 18:10:09 +02:00
let temp = tempfile::tempdir().unwrap();
2021-03-25 10:24:33 +01:00
2022-02-28 14:43:22 +01:00
let snapshot_path = snapshot_dir.path().to_owned().join("db.snapshot");
2021-03-25 10:24:33 +01:00
2022-10-20 18:00:07 +02:00
let options = Opt { import_snapshot: Some(snapshot_path), ..default_settings(temp.path()) };
2021-03-25 10:24:33 +01:00
2022-04-28 10:48:57 +02:00
let snapshot_server = Server::new_with_options(options).await.unwrap();
2021-03-25 10:24:33 +01:00
verify_snapshot!(server, snapshot_server, |server| =>
server.list_indexes(None, None),
// for some reason the db sizes differ. this may be due to the compaction options we have
// set when performing the snapshot
//server.stats(),
server.tasks(),
server.index("test").get_all_documents(GetAllDocumentsOptions::default()),
server.index("test").settings(),
server.index("test1").get_all_documents(GetAllDocumentsOptions::default()),
server.index("test1").settings(),
);
2021-03-25 10:24:33 +01:00
}