Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit d9c7dea

Browse files
committed
More test, fixed linting
1 parent f6c1301 commit d9c7dea

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

twistar/tests/test_transactions.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from twisted.trial import unittest
55
from twisted.internet import reactor
6-
from twisted.internet.defer import Deferred, inlineCallbacks, returnValue, maybeDeferred
6+
from twisted.internet.defer import Deferred, inlineCallbacks, returnValue, maybeDeferred, DeferredList
77
from twisted.python import threadable
88

99
from twistar.transaction import transaction, nested_transaction
@@ -232,6 +232,35 @@ def trans2(txn):
232232
count = yield Transaction.count()
233233
self.assertEqual(count, 1)
234234

235+
@inlineCallbacks
236+
def test_parallel_massive(self):
237+
# Make sure that everything works alright even when starting a massive amount of parallel transactions
238+
if DBTYPE == "sqlite":
239+
raise unittest.SkipTest("Parallel connections are not supported by sqlite")
240+
241+
N = 100
242+
243+
@transaction
244+
@inlineCallbacks
245+
def trans(txn, i):
246+
yield Transaction(name=str(i)).save()
247+
if i % 2 == 1:
248+
txn.rollback()
249+
else:
250+
txn.commit()
251+
252+
deferreds = [trans(i) for i in range(N)]
253+
254+
results = yield DeferredList(deferreds)
255+
self.assertTrue(all(success for success, result in results))
256+
257+
objects = yield Transaction.all()
258+
actual = sorted(int(obj.name) for obj in objects)
259+
actual = [str(i) for i in actual]
260+
expected = [str(i) for i in range(0, N, 2)]
261+
262+
self.assertEquals(actual, expected)
263+
235264
@inlineCallbacks
236265
def test_savepoints_commit(self):
237266
if DBTYPE == "sqlite":

0 commit comments

Comments
 (0)