Skip to content

Commit

Permalink
feat(torture):reverted changeset on previous state
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gabriele-0201 committed Jan 20, 2025
1 parent 7d8599d commit 4ea41bc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion torture/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub async fn run(input: UnixStream) -> Result<()> {
.await?;
}
ToAgent::Query(key) => {
trace!("query: {}", hex::encode(key));
let value = agent.query(key)?;
stream
.send(Envelope {
Expand Down
1 change: 0 additions & 1 deletion torture/src/supervisor/comms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl RequestResponse {
// Requests the value of the key from the agent.
#[allow(dead_code)]
pub async fn send_request_query(&self, key: message::Key) -> anyhow::Result<Option<Vec<u8>>> {
trace!(key = hex::encode(&key), "sending storage query");
match self
.send_request(crate::message::ToAgent::Query(key))
.await?
Expand Down
31 changes: 23 additions & 8 deletions torture/src/supervisor/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,31 @@ impl Workload {
// is equal to its previous state and that each new key is not avaible.
for change in changeset {
match change {
KeyValueChange::Insert(key, value)
if rr.send_request_query(*key).await?.as_ref() == Some(value) =>
{
return Err(anyhow::anyhow!("Inserted item should be reverted"));
KeyValueChange::Insert(key, _value) => {
// The current value must be equal to the previous one.
let current_value = rr.send_request_query(*key).await?;
match self.state.committed.state.get(key) {
None | Some(None) if current_value.is_some() => {
return Err(anyhow::anyhow!("New inserted item should not be present"));
}
Some(prev_value) if current_value != *prev_value => {
return Err(anyhow::anyhow!(
"Modified item should be reverted to previous state"
));
}
_ => (),
}
}
// This holds as long as we are sure that every deletions is done on present keys.
KeyValueChange::Delete(key) if rr.send_request_query(*key).await?.is_none() => {
return Err(anyhow::anyhow!("Deletion should have been reverted"));
KeyValueChange::Delete(key) => {
// UNWRAP: Non existing keys are not deleted.
let prev_value = self.state.committed.state.get(key).unwrap();
assert!(prev_value.is_some());
if rr.send_request_query(*key).await?.as_ref() != prev_value.as_ref() {
return Err(anyhow::anyhow!(
"Deleted item should be reverted to previous state"
));
}
}
_ => (),
}
}
Ok(())
Expand Down

0 comments on commit 4ea41bc

Please sign in to comment.