From d36a5dcd91a3b4a3118ea0b26e669f1462319b76 Mon Sep 17 00:00:00 2001 From: gabriele-0201 Date: Fri, 17 Jan 2025 15:53:13 +0100 Subject: [PATCH] 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. --- torture/src/agent.rs | 1 - torture/src/supervisor/comms.rs | 1 - torture/src/supervisor/workload.rs | 31 ++++++++++++++++++++++-------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/torture/src/agent.rs b/torture/src/agent.rs index f14b0926..9f7a1abe 100644 --- a/torture/src/agent.rs +++ b/torture/src/agent.rs @@ -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 { diff --git a/torture/src/supervisor/comms.rs b/torture/src/supervisor/comms.rs index a6960d92..e1c77da0 100644 --- a/torture/src/supervisor/comms.rs +++ b/torture/src/supervisor/comms.rs @@ -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>> { - trace!(key = hex::encode(&key), "sending storage query"); match self .send_request(crate::message::ToAgent::Query(key)) .await? diff --git a/torture/src/supervisor/workload.rs b/torture/src/supervisor/workload.rs index cf435074..cd8000c9 100644 --- a/torture/src/supervisor/workload.rs +++ b/torture/src/supervisor/workload.rs @@ -406,16 +406,31 @@ impl Workload { // is equal to its previous state and that each new key is not available. 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(())