Skip to content

Commit 59919f9

Browse files
committed
test: add an integration test for duplicate keys insertion and delete-your-writes
Signed-off-by: Ziyi Yan <[email protected]>
1 parent f8a086e commit 59919f9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/integration_tests.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,31 @@ async fn crud() -> Result<()> {
132132
Ok(())
133133
}
134134

135+
// Tests transactional insert and delete-your-writes cases
136+
#[tokio::test]
137+
#[serial]
138+
async fn insert_duplicate_keys() -> Result<()> {
139+
clear_tikv().await?;
140+
141+
let client = TransactionClient::new(pd_addrs()).await?;
142+
// Initialize TiKV store with {foo => bar}
143+
let mut txn = client.begin_optimistic().await?;
144+
txn.put("foo".to_owned(), "bar".to_owned()).await?;
145+
txn.commit().await?;
146+
// Try insert foo again
147+
let mut txn = client.begin_optimistic().await?;
148+
txn.insert("foo".to_owned(), "foo".to_owned()).await?;
149+
assert!(txn.commit().await.is_err());
150+
151+
// Delete-your-writes
152+
let mut txn = client.begin_optimistic().await?;
153+
txn.insert("foo".to_owned(), "foo".to_owned()).await?;
154+
txn.delete("foo".to_owned()).await?;
155+
assert!(txn.commit().await.is_err());
156+
157+
Ok(())
158+
}
159+
135160
#[tokio::test]
136161
#[serial]
137162
async fn pessimistic() -> Result<()> {

0 commit comments

Comments
 (0)