Skip to content

Commit e6340b2

Browse files
authored
Make bwc test fail if anything changes (#3375)
Fixes regression that was missing changes in the current serialization version. Fixes #3374
1 parent 5e430fe commit e6340b2

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

quickwit/quickwit-metastore/src/backward_compatibility_tests/mod.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,40 @@ where for<'a> T: Serialize {
145145
let mut sample_json = serde_json::to_string_pretty(&sample_json_value)?;
146146
sample_json.push('\n');
147147
let test_name = format!("v{version}");
148-
let file_regression_test_path = format!("{}/{}.json", test_dir.display(), test_name);
149-
let file_regression_expected_path =
148+
let file_regression_test_path_str = format!("{}/{}.json", test_dir.display(), test_name);
149+
let file_regression_expected_path_str =
150150
format!("{}/{}.expected.json", test_dir.display(), test_name);
151-
std::fs::write(file_regression_test_path, sample_json.as_bytes())?;
152-
std::fs::write(file_regression_expected_path, sample_json.as_bytes())?;
151+
152+
let file_regression_test_path = Path::new(&file_regression_test_path_str);
153+
let (changes_detected, file_created) = if file_regression_test_path.try_exists()? {
154+
let expected_old_json_value: JsonValue = deserialize_json_file(file_regression_test_path)?;
155+
let expected_new_json_value: JsonValue = serde_json::from_str(&sample_json)?;
156+
(expected_old_json_value != expected_new_json_value, false)
157+
} else {
158+
(false, true)
159+
};
160+
161+
if changes_detected || file_created {
162+
std::fs::write(
163+
file_regression_test_path_str.clone(),
164+
sample_json.as_bytes(),
165+
)?;
166+
std::fs::write(
167+
file_regression_expected_path_str.clone(),
168+
sample_json.as_bytes(),
169+
)?;
170+
if file_created {
171+
panic!(
172+
"The following files need to be added: {file_regression_test_path_str:?} and \
173+
{file_regression_expected_path_str:?}"
174+
)
175+
} else {
176+
panic!(
177+
"The following files need to be updated: {file_regression_test_path_str:?} and \
178+
{file_regression_expected_path_str:?}"
179+
)
180+
}
181+
}
153182
Ok(())
154183
}
155184

quickwit/quickwit-metastore/test-data/file-backed-index/v0.6.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"create_timestamp": 0,
55
"delete_query": {
66
"index_uid": "index:1111111111111",
7-
"query_ast": "{\"type\":\"Bool\",\"must\":[{\"type\":\"Phrase\",\"field\":\"body\",\"phrase\":\"Harry\"},{\"type\":\"Phrase\",\"field\":\"body\",\"phrase\":\"Potter\"}]}"
7+
"query_ast": "{\"type\":\"bool\",\"must\":[{\"type\":\"full_text\",\"field\":\"body\",\"text\":\"Harry\",\"params\":{\"mode\":{\"type\":\"phrase\"}}},{\"type\":\"full_text\",\"field\":\"body\",\"text\":\"Potter\",\"params\":{\"mode\":{\"type\":\"phrase\"}}}]}"
88
},
99
"opstamp": 10
1010
}

quickwit/quickwit-metastore/test-data/file-backed-index/v0.6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"create_timestamp": 0,
55
"delete_query": {
66
"index_uid": "index:1111111111111",
7-
"query_ast": "{\"type\":\"Bool\",\"must\":[{\"type\":\"Phrase\",\"field\":\"body\",\"phrase\":\"Harry\"},{\"type\":\"Phrase\",\"field\":\"body\",\"phrase\":\"Potter\"}]}"
7+
"query_ast": "{\"type\":\"bool\",\"must\":[{\"type\":\"full_text\",\"field\":\"body\",\"text\":\"Harry\",\"params\":{\"mode\":{\"type\":\"phrase\"}}},{\"type\":\"full_text\",\"field\":\"body\",\"text\":\"Potter\",\"params\":{\"mode\":{\"type\":\"phrase\"}}}]}"
88
},
99
"opstamp": 10
1010
}

0 commit comments

Comments
 (0)