Skip to content

Commit 6361a18

Browse files
committed
feat(torture):reverted changeset on previous state
Make sure that any reverted changes did not alter already present values. To do this, compare them with the values of the previous state maintained by the supervisor.
1 parent 7d8599d commit 6361a18

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

torture/src/supervisor/workload.rs

+28-8
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,36 @@ impl Workload {
404404
// is equal to its previous state and that each new key is not avaible.
405405
for change in changeset {
406406
match change {
407-
KeyValueChange::Insert(key, value)
408-
if rr.send_request_query(*key).await?.as_ref() == Some(value) =>
409-
{
410-
return Err(anyhow::anyhow!("Inserted item should be reverted"));
407+
KeyValueChange::Insert(key, _value) => {
408+
let Some(prev_value) = self.state.committed.state.get(key) else {
409+
// if the key was not present in the previous state,
410+
// it must be a new key. Thus None is expected
411+
if rr.send_request_query(*key).await?.is_some() {
412+
return Err(anyhow::anyhow!("New inserted item should not be present"));
413+
}
414+
continue;
415+
};
416+
417+
if rr.send_request_query(*key).await? != *prev_value {
418+
let err = if prev_value.is_some() {
419+
"Modified item should be reverted to previous state"
420+
} else {
421+
"New inserted item should not be present"
422+
};
423+
return Err(anyhow::anyhow!(err));
424+
}
411425
}
412-
// This holds as long as we are sure that every deletions is done on present keys.
413-
KeyValueChange::Delete(key) if rr.send_request_query(*key).await?.is_none() => {
414-
return Err(anyhow::anyhow!("Deletion should have been reverted"));
426+
KeyValueChange::Delete(key) => {
427+
// UNWRAP: Non existing keys are not deleted
428+
let prev_value = self.state.committed.state.get(key).unwrap();
429+
if rr.send_request_query(*key).await? != *prev_value {
430+
// Non existing keys are not deleted
431+
assert!(prev_value.is_some());
432+
return Err(anyhow::anyhow!(
433+
"Deleted item should be reverted to previous state"
434+
));
435+
}
415436
}
416-
_ => (),
417437
}
418438
}
419439
Ok(())

0 commit comments

Comments
 (0)