Skip to content

Commit

Permalink
fix: remove flaky test (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
arriqaaq authored Dec 5, 2024
1 parent 579c6bb commit 767752b
Showing 1 changed file with 0 additions and 96 deletions.
96 changes: 0 additions & 96 deletions src/storage/kv/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1968,100 +1968,4 @@ mod tests {
total_tasks, final_count
);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_incremental_transaction_ids_concurrent() {
for is_ssi in [false, true] {
let (store, temp_dir) = create_store(None, is_ssi);
let store = Arc::new(store);

let total_records = 1000;
let multiple_keys_records = total_records / 2;

// Define keys and values
let keys: Vec<Bytes> = (1..=total_records)
.map(|i| Bytes::from(format!("key{}", i)))
.collect();
let values: Vec<Bytes> = (1..=total_records)
.map(|i| Bytes::from(format!("value{}", i)))
.collect();

// Insert multiple transactions with single keys concurrently
let mut tasks = Vec::new();
for (i, key) in keys.iter().enumerate().take(multiple_keys_records) {
let store = store.clone();
let key = key.clone();
let value = values[i].clone();
tasks.push(tokio::spawn(async move {
let mut txn = store.begin().unwrap();
txn.set(&key, &value).unwrap();
txn.commit().await.unwrap();
}));
}

// Wait for all tasks to complete
for task in tasks {
task.await.unwrap();
}

// Insert multiple transactions with multiple keys concurrently
let mut tasks = Vec::new();
for (i, key) in keys
.iter()
.enumerate()
.skip(multiple_keys_records)
.take(multiple_keys_records)
{
let store = store.clone();
let key = key.clone();
let value = values[i].clone();
let next_key = keys[(i + multiple_keys_records) % keys.len()].clone();
let next_value = values[(i + multiple_keys_records) % values.len()].clone();
tasks.push(tokio::spawn(async move {
let mut txn = store.begin().unwrap();
txn.set(&key, &value).unwrap();
txn.set(&next_key, &next_value).unwrap();
txn.commit().await.unwrap();
}));
}

// Wait for all tasks to complete
for task in tasks {
task.await.unwrap();
}
// Close the store
store.close().await.unwrap();

// Add delay to ensure that the store is closed
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;

// Reopen the store
let (store, _) = create_store(Some(temp_dir), is_ssi);

// Commit a new transaction with a single key
{
let mut txn = store.begin().unwrap();
txn.set(&keys[0], &values[0]).unwrap();
txn.commit().await.unwrap();

let res = txn.get_versionstamp().unwrap();

assert_eq!(res.0, total_records as u64 + 1);
}

// Commit another new transaction with multiple keys
{
let mut txn = store.begin().unwrap();
txn.set(&keys[1], &values[1]).unwrap();
txn.set(&keys[2], &values[2]).unwrap();
txn.commit().await.unwrap();

let res = txn.get_versionstamp().unwrap();

assert_eq!(res.0, total_records as u64 + 2);
}

store.close().await.unwrap();
}
}
}

0 comments on commit 767752b

Please sign in to comment.