Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acerone85 committed Oct 3, 2024
1 parent 5088796 commit eb20535
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion crates/fuel-core/src/state/historical_rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,23 @@ where
self.modifications_history_migration_in_progress
.store(false, Release);
}

pub fn check_and_update_migration_status(&self) -> bool {
let result = self.v1_entries().next().is_some();
// Other threads will need to synchronise with this store operation
// when checking the migration status, hence we set the ordering to Release
self.modifications_history_migration_in_progress
.store(result, Release);

result
}

#[cfg(test)]
fn commit_migration_changes(&self) -> StorageResult<()> {
self.db.commit_changes(&std::mem::take(
&mut *self.migration_changes.lock().unwrap(),
))
}
}

// Try to take the value from `ModificationsHistoryV2` first.
Expand Down Expand Up @@ -1116,7 +1133,7 @@ mod tests {
}

#[test]
fn state_rewind_policy__rewind_range_1__migrate_modifications_history_works() {
fn migrate_modifications_history_works() {
// Given
let rocks_db = RocksDb::<Historical<OnChain>>::default_open_temp(None).unwrap();
let historical_rocks_db = HistoricalRocksDB::new(
Expand Down Expand Up @@ -1177,6 +1194,28 @@ mod tests {
.migrate_modifications_history_at_height(1u64)
.unwrap();

// Check that the changes are not written to the database yet
let v2_entries = historical_rocks_db
.db
.iter_all::<ModificationsHistoryV2<OnChain>>(None)
.collect::<Vec<_>>();
let v1_entries = historical_rocks_db
.db
.iter_all::<ModificationsHistoryV1<OnChain>>(None)
.collect::<Vec<_>>();

assert_eq!(v2_entries.len(), 0);
assert_eq!(v1_entries.len(), 1);

// Check that the migration is still in progress.
assert_eq!(
historical_rocks_db.check_and_update_migration_status(),
true
);

// Flush the changes to the DB
historical_rocks_db.commit_migration_changes().unwrap();

// Then
let v2_entries = historical_rocks_db
.db
Expand All @@ -1189,6 +1228,11 @@ mod tests {

assert_eq!(v2_entries.len(), 1);
assert_eq!(v1_entries.len(), 0);

assert_eq!(
historical_rocks_db.check_and_update_migration_status(),
false
);
}

#[test]
Expand Down

0 comments on commit eb20535

Please sign in to comment.