Skip to content

Commit 3349687

Browse files
committed
Update transaction tests.
1 parent 75c35dd commit 3349687

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

tests/test_transactions.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,39 @@
66

77

88
def test_simple(t: Testing):
9+
t.source["db_1"].create_collection("coll_1")
10+
t.source["db_2"].create_collection("coll_2")
11+
912
with t.run(phase=Runner.Phase.APPLY):
1013
with t.source.start_session() as sess:
1114
sess.start_transaction()
1215
t.source["db_1"]["coll_1"].insert_one({"i": 1}, session=sess)
1316
t.source["db_2"]["coll_2"].insert_one({"i": 2}, session=sess)
1417
sess.commit_transaction()
1518

16-
assert t.source["db_1"]["coll_1"].count_documents({}) == 1
19+
20+
t.source["db_1"]["coll_1"].insert_one({"i": 2})
21+
22+
assert t.source["db_1"]["coll_1"].count_documents({}) == 2
1723
assert t.source["db_2"]["coll_2"].count_documents({}) == 1
1824

1925
t.compare_all()
2026

2127

2228
def test_simple_aborted(t: Testing):
29+
t.source["db_1"].create_collection("coll_1")
30+
t.source["db_2"].create_collection("coll_2")
31+
2332
with t.run(phase=Runner.Phase.APPLY):
2433
with t.source.start_session() as sess:
2534
sess.start_transaction()
2635
t.source["db_1"]["coll_1"].insert_one({"i": 1}, session=sess)
2736
t.source["db_2"]["coll_2"].insert_one({"i": 2}, session=sess)
2837
sess.abort_transaction()
2938

30-
assert "db_1" not in t.source.list_database_names()
31-
assert "db_2" not in t.source.list_database_names()
39+
t.source["db_1"]["coll_1"].insert_one({"i": 2})
40+
41+
assert t.source["db_1"]["coll_1"].count_documents({}) == 1
3242

3343
t.compare_all()
3444

@@ -81,6 +91,8 @@ def test_mixed_with_non_trx_ops_aborted(t: Testing):
8191

8292

8393
def test_in_progress(t: Testing):
94+
t.source["db_1"].create_collection("coll_1")
95+
8496
with t.source.start_session() as sess:
8597
sess.start_transaction()
8698
t.source["db_1"]["coll_1"].insert_one({"i": 1, "trx": 1}, session=sess)
@@ -89,7 +101,9 @@ def test_in_progress(t: Testing):
89101
t.source["db_1"]["coll_1"].insert_one({"i": 2, "trx": 1}, session=sess)
90102
sess.commit_transaction()
91103

92-
assert t.source["db_1"]["coll_1"].count_documents({}) == 2
104+
t.source["db_1"]["coll_1"].insert_one({"i": 3})
105+
106+
assert t.source["db_1"]["coll_1"].count_documents({}) == 3
93107

94108
t.compare_all()
95109

@@ -188,6 +202,8 @@ def run_transaction_1():
188202
t.source["db_1"]["coll_1"].insert_one({"i": 2, "trx": 1}, session=sess)
189203
sess.commit_transaction()
190204

205+
t.source["db_1"]["coll_1"].insert_one({"i": 10})
206+
191207
def run_transaction_2():
192208
with t.source.start_session() as sess:
193209
sess.start_transaction()
@@ -197,6 +213,8 @@ def run_transaction_2():
197213
event_2.set()
198214
sess.abort_transaction()
199215

216+
t.source["db_2"]["coll_2"].insert_one({"i": 10})
217+
200218
with t.run(Runner.Phase.APPLY):
201219
thread1 = threading.Thread(target=run_transaction_1)
202220
thread2 = threading.Thread(target=run_transaction_2)
@@ -207,8 +225,9 @@ def run_transaction_2():
207225
thread1.join()
208226
thread2.join()
209227

210-
assert t.source["db_1"]["coll_1"].count_documents({}) == 2
211-
assert "db_2" not in t.source.list_database_names()
228+
assert t.source["db_1"]["coll_1"].count_documents({}) == 3
229+
assert t.source["db_2"]["coll_2"].count_documents({}) == 1
230+
# assert "db_2" not in t.source.list_database_names()
212231

213232
t.compare_all()
214233

0 commit comments

Comments
 (0)