From 8d94939aac9f99f5304e39ea48e4ecf0f6711e3f Mon Sep 17 00:00:00 2001 From: avi-starkware Date: Tue, 28 May 2024 09:54:46 +0300 Subject: [PATCH] test(concurrency): test finish_execution_during_commit (#1904) --- crates/blockifier/src/concurrency/scheduler.rs | 4 +--- .../blockifier/src/concurrency/scheduler_test.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/blockifier/src/concurrency/scheduler.rs b/crates/blockifier/src/concurrency/scheduler.rs index 72d04cff58..43e9168125 100644 --- a/crates/blockifier/src/concurrency/scheduler.rs +++ b/crates/blockifier/src/concurrency/scheduler.rs @@ -106,9 +106,7 @@ impl Scheduler { /// already scheduled. pub fn finish_execution(&self, tx_index: TxIndex) { self.set_executed_status(tx_index); - if self.validation_index.load(Ordering::Acquire) > tx_index { - self.decrease_validation_index(tx_index); - } + self.decrease_validation_index(tx_index); } pub fn try_validation_abort(&self, tx_index: TxIndex) -> bool { diff --git a/crates/blockifier/src/concurrency/scheduler_test.rs b/crates/blockifier/src/concurrency/scheduler_test.rs index 33284aa153..a9a0a7a711 100644 --- a/crates/blockifier/src/concurrency/scheduler_test.rs +++ b/crates/blockifier/src/concurrency/scheduler_test.rs @@ -122,6 +122,21 @@ fn test_commit_flow( } } +#[rstest] +#[case::reduces_validation_index(0, 3)] +#[case::does_not_reduce_validation_index(1, 0)] +fn test_finish_execution_during_commit( + #[case] tx_index: TxIndex, + #[case] validation_index: TxIndex, +) { + let target_index = tx_index + 1; + let scheduler = + default_scheduler!(chunk_size: DEFAULT_CHUNK_SIZE, validation_index: validation_index); + scheduler.finish_execution_during_commit(tx_index); + let expected_validation_index = min(target_index, validation_index); + assert_eq!(scheduler.validation_index.load(Ordering::Acquire), expected_validation_index); +} + #[rstest] #[case::happy_flow(TransactionStatus::Executing)] #[should_panic(expected = "Only executing transactions can gain status executed. Transaction 0 \