reduce the size of the snapshots

This commit is contained in:
Tamo 2022-09-15 12:32:27 +02:00 committed by Clément Renault
parent 7d0c8a3379
commit 5436b996ab
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 73 additions and 745 deletions

View File

@ -373,8 +373,9 @@ pub fn autobatch(enqueued: Vec<(TaskId, Kind)>) -> Option<BatchKind> {
#[cfg(test)]
mod tests {
use crate::assert_smol_debug_snapshot;
use super::*;
use insta::*;
use Kind::*;
fn input_from(input: impl IntoIterator<Item = Kind>) -> Vec<(TaskId, Kind)> {
@ -388,798 +389,125 @@ mod tests {
#[test]
fn autobatch_simple_operation_together() {
// we can autobatch one or multiple DocumentAddition together
assert_debug_snapshot!(autobatch(input_from([DocumentAddition])), @r###"
Some(
DocumentAddition {
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, DocumentAddition])), @r###"
Some(
DocumentAddition {
addition_ids: [
0,
1,
2,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition])), @"Some(DocumentAddition { addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, DocumentAddition])), @"Some(DocumentAddition { addition_ids: [0, 1, 2] })");
// we can autobatch one or multiple DocumentUpdate together
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate])), @r###"
Some(
DocumentUpdate {
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentUpdate, DocumentUpdate])), @r###"
Some(
DocumentUpdate {
update_ids: [
0,
1,
2,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate])), @"Some(DocumentUpdate { update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentUpdate, DocumentUpdate])), @"Some(DocumentUpdate { update_ids: [0, 1, 2] })");
// we can autobatch one or multiple DocumentDeletion together
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion])), @r###"
Some(
DocumentDeletion {
deletion_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion, DocumentDeletion, DocumentDeletion])), @r###"
Some(
DocumentDeletion {
deletion_ids: [
0,
1,
2,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion])), @"Some(DocumentDeletion { deletion_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion, DocumentDeletion, DocumentDeletion])), @"Some(DocumentDeletion { deletion_ids: [0, 1, 2] })");
// we can autobatch one or multiple Settings together
assert_debug_snapshot!(autobatch(input_from([Settings])), @r###"
Some(
Settings {
settings_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([Settings, Settings, Settings])), @r###"
Some(
Settings {
settings_ids: [
0,
1,
2,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([Settings])), @"Some(Settings { settings_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([Settings, Settings, Settings])), @"Some(Settings { settings_ids: [0, 1, 2] })");
}
#[test]
fn simple_document_operation_dont_autobatch_with_other() {
// addition, updates and deletion can't batch together
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentUpdate])), @r###"
Some(
DocumentAddition {
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentDeletion])), @r###"
Some(
DocumentAddition {
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentAddition])), @r###"
Some(
DocumentUpdate {
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentDeletion])), @r###"
Some(
DocumentUpdate {
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion, DocumentAddition])), @r###"
Some(
DocumentDeletion {
deletion_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion, DocumentUpdate])), @r###"
Some(
DocumentDeletion {
deletion_ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentUpdate])), @"Some(DocumentAddition { addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentDeletion])), @"Some(DocumentAddition { addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentAddition])), @"Some(DocumentUpdate { update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentDeletion])), @"Some(DocumentUpdate { update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion, DocumentAddition])), @"Some(DocumentDeletion { deletion_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion, DocumentUpdate])), @"Some(DocumentDeletion { deletion_ids: [0] })");
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexCreation])), @r###"
Some(
DocumentAddition {
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexCreation])), @r###"
Some(
DocumentUpdate {
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexCreation])), @r###"
Some(
DocumentDeletion {
deletion_ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexCreation])), @"Some(DocumentAddition { addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexCreation])), @"Some(DocumentUpdate { update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexCreation])), @"Some(DocumentDeletion { deletion_ids: [0] })");
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexUpdate])), @r###"
Some(
DocumentAddition {
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexUpdate])), @r###"
Some(
DocumentUpdate {
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexUpdate])), @r###"
Some(
DocumentDeletion {
deletion_ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexUpdate])), @"Some(DocumentAddition { addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexUpdate])), @"Some(DocumentUpdate { update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexUpdate])), @"Some(DocumentDeletion { deletion_ids: [0] })");
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexRename])), @r###"
Some(
DocumentAddition {
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexRename])), @r###"
Some(
DocumentUpdate {
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexRename])), @r###"
Some(
DocumentDeletion {
deletion_ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexRename])), @"Some(DocumentAddition { addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexRename])), @"Some(DocumentUpdate { update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexRename])), @"Some(DocumentDeletion { deletion_ids: [0] })");
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexSwap])), @r###"
Some(
DocumentAddition {
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexSwap])), @r###"
Some(
DocumentUpdate {
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexSwap])), @r###"
Some(
DocumentDeletion {
deletion_ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexSwap])), @"Some(DocumentAddition { addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexSwap])), @"Some(DocumentUpdate { update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexSwap])), @"Some(DocumentDeletion { deletion_ids: [0] })");
}
#[test]
fn document_addition_batch_with_settings() {
// simple case
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
1,
],
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings])), @r###"
Some(
SettingsAndDocumentUpdate {
settings_ids: [
1,
],
update_ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings])), @"Some(SettingsAndDocumentAddition { settings_ids: [1], addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings])), @"Some(SettingsAndDocumentUpdate { settings_ids: [1], update_ids: [0] })");
// multiple settings and doc addition
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, Settings, Settings])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
2,
3,
],
addition_ids: [
0,
1,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, Settings, Settings])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
2,
3,
],
addition_ids: [
0,
1,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, Settings, Settings])), @"Some(SettingsAndDocumentAddition { settings_ids: [2, 3], addition_ids: [0, 1] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, Settings, Settings])), @"Some(SettingsAndDocumentAddition { settings_ids: [2, 3], addition_ids: [0, 1] })");
// addition and setting unordered
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentAddition, Settings])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
1,
3,
],
addition_ids: [
0,
2,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentUpdate, Settings])), @r###"
Some(
SettingsAndDocumentUpdate {
settings_ids: [
1,
3,
],
update_ids: [
0,
2,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentAddition, Settings])), @"Some(SettingsAndDocumentAddition { settings_ids: [1, 3], addition_ids: [0, 2] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentUpdate, Settings])), @"Some(SettingsAndDocumentUpdate { settings_ids: [1, 3], update_ids: [0, 2] })");
// We ensure this kind of batch doesn't batch with forbidden operations
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentUpdate])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
1,
],
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentAddition])), @r###"
Some(
SettingsAndDocumentUpdate {
settings_ids: [
1,
],
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentDeletion])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
1,
],
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentDeletion])), @r###"
Some(
SettingsAndDocumentUpdate {
settings_ids: [
1,
],
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexCreation])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
1,
],
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexCreation])), @r###"
Some(
SettingsAndDocumentUpdate {
settings_ids: [
1,
],
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexUpdate])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
1,
],
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexUpdate])), @r###"
Some(
SettingsAndDocumentUpdate {
settings_ids: [
1,
],
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexRename])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
1,
],
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexRename])), @r###"
Some(
SettingsAndDocumentUpdate {
settings_ids: [
1,
],
update_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexSwap])), @r###"
Some(
SettingsAndDocumentAddition {
settings_ids: [
1,
],
addition_ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexSwap])), @r###"
Some(
SettingsAndDocumentUpdate {
settings_ids: [
1,
],
update_ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentUpdate])), @"Some(SettingsAndDocumentAddition { settings_ids: [1], addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentAddition])), @"Some(SettingsAndDocumentUpdate { settings_ids: [1], update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentDeletion])), @"Some(SettingsAndDocumentAddition { settings_ids: [1], addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentDeletion])), @"Some(SettingsAndDocumentUpdate { settings_ids: [1], update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexCreation])), @"Some(SettingsAndDocumentAddition { settings_ids: [1], addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexCreation])), @"Some(SettingsAndDocumentUpdate { settings_ids: [1], update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexUpdate])), @"Some(SettingsAndDocumentAddition { settings_ids: [1], addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexUpdate])), @"Some(SettingsAndDocumentUpdate { settings_ids: [1], update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexRename])), @"Some(SettingsAndDocumentAddition { settings_ids: [1], addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexRename])), @"Some(SettingsAndDocumentUpdate { settings_ids: [1], update_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexSwap])), @"Some(SettingsAndDocumentAddition { settings_ids: [1], addition_ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexSwap])), @"Some(SettingsAndDocumentUpdate { settings_ids: [1], update_ids: [0] })");
}
#[test]
fn clear_and_additions() {
// these two doesn't need to batch
assert_debug_snapshot!(autobatch(input_from([DocumentClear, DocumentAddition])), @r###"
Some(
DocumentClear {
ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentClear, DocumentUpdate])), @r###"
Some(
DocumentClear {
ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentClear, DocumentAddition])), @"Some(DocumentClear { ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentClear, DocumentUpdate])), @"Some(DocumentClear { ids: [0] })");
// Basic use case
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, DocumentClear])), @r###"
Some(
DocumentClear {
ids: [
0,
1,
2,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentUpdate, DocumentClear])), @r###"
Some(
DocumentClear {
ids: [
0,
1,
2,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, DocumentClear])), @"Some(DocumentClear { ids: [0, 1, 2] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentUpdate, DocumentClear])), @"Some(DocumentClear { ids: [0, 1, 2] })");
// This batch kind doesn't mix with other document addition
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, DocumentClear, DocumentAddition])), @r###"
Some(
DocumentClear {
ids: [
0,
1,
2,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentUpdate, DocumentClear, DocumentUpdate])), @r###"
Some(
DocumentClear {
ids: [
0,
1,
2,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, DocumentClear, DocumentAddition])), @"Some(DocumentClear { ids: [0, 1, 2] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentUpdate, DocumentClear, DocumentUpdate])), @"Some(DocumentClear { ids: [0, 1, 2] })");
// But you can batch multiple clear together
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, DocumentClear, DocumentClear, DocumentClear])), @r###"
Some(
DocumentClear {
ids: [
0,
1,
2,
3,
4,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentUpdate, DocumentClear, DocumentClear, DocumentClear])), @r###"
Some(
DocumentClear {
ids: [
0,
1,
2,
3,
4,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, DocumentAddition, DocumentClear, DocumentClear, DocumentClear])), @"Some(DocumentClear { ids: [0, 1, 2, 3, 4] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, DocumentUpdate, DocumentClear, DocumentClear, DocumentClear])), @"Some(DocumentClear { ids: [0, 1, 2, 3, 4] })");
}
#[test]
fn clear_and_additions_and_settings() {
// A clear don't need to autobatch the settings that happens AFTER there is no documents
assert_debug_snapshot!(autobatch(input_from([DocumentClear, Settings])), @r###"
Some(
DocumentClear {
ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentClear, Settings])), @"Some(DocumentClear { ids: [0] })");
assert_debug_snapshot!(autobatch(input_from([Settings, DocumentClear, Settings])), @r###"
Some(
ClearAndSettings {
other: [
1,
],
settings_ids: [
0,
2,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentClear])), @r###"
Some(
ClearAndSettings {
other: [
0,
2,
],
settings_ids: [
1,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentClear])), @r###"
Some(
ClearAndSettings {
other: [
0,
2,
],
settings_ids: [
1,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([Settings, DocumentClear, Settings])), @"Some(ClearAndSettings { other: [1], settings_ids: [0, 2] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentClear])), @"Some(ClearAndSettings { other: [0, 2], settings_ids: [1] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentClear])), @"Some(ClearAndSettings { other: [0, 2], settings_ids: [1] })");
}
#[test]
fn anything_and_index_deletion() {
// The indexdeletion doesn't batch with anything that happens AFTER
assert_debug_snapshot!(autobatch(input_from([IndexDeletion, DocumentAddition])), @r###"
Some(
IndexDeletion {
ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([IndexDeletion, DocumentUpdate])), @r###"
Some(
IndexDeletion {
ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([IndexDeletion, DocumentDeletion])), @r###"
Some(
IndexDeletion {
ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([IndexDeletion, DocumentClear])), @r###"
Some(
IndexDeletion {
ids: [
0,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([IndexDeletion, Settings])), @r###"
Some(
IndexDeletion {
ids: [
0,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([IndexDeletion, DocumentAddition])), @"Some(IndexDeletion { ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([IndexDeletion, DocumentUpdate])), @"Some(IndexDeletion { ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([IndexDeletion, DocumentDeletion])), @"Some(IndexDeletion { ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([IndexDeletion, DocumentClear])), @"Some(IndexDeletion { ids: [0] })");
assert_smol_debug_snapshot!(autobatch(input_from([IndexDeletion, Settings])), @"Some(IndexDeletion { ids: [0] })");
// The index deletion can accept almost any type of BatchKind and transform it to an IndexDeletion
// First, the basic cases
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
0,
1,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
0,
1,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
0,
1,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentClear, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
0,
1,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([Settings, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
0,
1,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, IndexDeletion])), @"Some(IndexDeletion { ids: [0, 1] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, IndexDeletion])), @"Some(IndexDeletion { ids: [0, 1] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentDeletion, IndexDeletion])), @"Some(IndexDeletion { ids: [0, 1] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentClear, IndexDeletion])), @"Some(IndexDeletion { ids: [0, 1] })");
assert_smol_debug_snapshot!(autobatch(input_from([Settings, IndexDeletion])), @"Some(IndexDeletion { ids: [0, 1] })");
// Then the mixed cases
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
0,
2,
1,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
0,
2,
1,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentClear, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
1,
3,
0,
2,
],
},
)
"###);
assert_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentClear, IndexDeletion])), @r###"
Some(
IndexDeletion {
ids: [
1,
3,
0,
2,
],
},
)
"###);
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, IndexDeletion])), @"Some(IndexDeletion { ids: [0, 2, 1] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, IndexDeletion])), @"Some(IndexDeletion { ids: [0, 2, 1] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentAddition, Settings, DocumentClear, IndexDeletion])), @"Some(IndexDeletion { ids: [1, 3, 0, 2] })");
assert_smol_debug_snapshot!(autobatch(input_from([DocumentUpdate, Settings, DocumentClear, IndexDeletion])), @"Some(IndexDeletion { ids: [1, 3, 0, 2] })");
}
}

View File

@ -487,7 +487,7 @@ mod tests {
all_tasks.push(ret.unwrap());
}
assert_smol_debug_snapshot!(all_tasks, @r###"[(U32(0), Task { uid: 0, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 20, second: 33, nanosecond: 531850695 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") } }), (U32(1), Task { uid: 1, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 20, second: 33, nanosecond: 531928625 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: DocumentAddition { index_uid: "catto", primary_key: None, content_file: c0d2f89e-a2ea-4357-a3ea-8c3135d1e9c7, documents_count: 12, allow_index_creation: true } }), (U32(2), Task { uid: 2, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 20, second: 33, nanosecond: 531966226 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: CancelTask { tasks: [0, 1] } }), (U32(3), Task { uid: 3, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 20, second: 33, nanosecond: 531997016 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: DocumentAddition { index_uid: "catto", primary_key: None, content_file: 84aa6582-645c-4347-abbe-32cb85d488a8, documents_count: 50, allow_index_creation: true } }), (U32(4), Task { uid: 4, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 20, second: 33, nanosecond: 532027497 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: DocumentAddition { index_uid: "doggo", primary_key: Some("bone"), content_file: 4335f1d6-0cab-4474-beef-5d564f23f5a0, documents_count: 5000, allow_index_creation: true } })]"###);
assert_smol_debug_snapshot!(all_tasks, @r###"[(U32(0), Task { uid: 0, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 29, second: 58, nanosecond: 423000426 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") } }), (U32(1), Task { uid: 1, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 29, second: 58, nanosecond: 423082546 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: DocumentAddition { index_uid: "catto", primary_key: None, content_file: b1d69015-c24b-446b-a736-d69ce2178279, documents_count: 12, allow_index_creation: true } }), (U32(2), Task { uid: 2, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 29, second: 58, nanosecond: 423117327 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: CancelTask { tasks: [0, 1] } }), (U32(3), Task { uid: 3, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 29, second: 58, nanosecond: 423146917 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: DocumentAddition { index_uid: "catto", primary_key: None, content_file: ff0a9258-88c5-4517-9f31-2a9bda25f8fb, documents_count: 50, allow_index_creation: true } }), (U32(4), Task { uid: 4, enqueued_at: OffsetDateTime { local_datetime: PrimitiveDateTime { date: Date { year: 2022, ordinal: 258 }, time: Time { hour: 10, minute: 29, second: 58, nanosecond: 423174667 } }, offset: UtcOffset { hours: 0, minutes: 0, seconds: 0 } }, started_at: None, finished_at: None, error: None, details: None, status: Enqueued, kind: DocumentAddition { index_uid: "doggo", primary_key: Some("bone"), content_file: 3eaff0f8-42f2-4d35-bf01-f47623dbd932, documents_count: 5000, allow_index_creation: true } })]"###);
let mut status = Vec::new();
for ret in index_scheduler.status.iter(&rtxn).unwrap() {