Skip to content

Commit

Permalink
Add basic test to run several transactions in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
rudyryk committed Feb 19, 2016
1 parent 41aa358 commit 780be2f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/tests_py35.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
will just fail with `SyntaxError` while importing this module.
"""
import asyncio
import peewee_async
from . import database,\
BaseAsyncPostgresTestCase,\
Expand Down Expand Up @@ -68,3 +69,27 @@ async def test():
self.assertEqual(res.text, 'FOO')

self.run_until_complete(test())

def test_several_transactions(self):
"""Run several transactions in parallel tasks.
"""
async def t1():
async with database.atomic_async():
self.assertEqual(database.transaction_depth(), 1)
await asyncio.sleep(0.5)

async def t2():
async with database.atomic_async():
self.assertEqual(database.transaction_depth(), 1)
await asyncio.sleep(1.0)

async def t3():
async with database.atomic_async():
self.assertEqual(database.transaction_depth(), 1)
await asyncio.sleep(1.5)

self.run_until_complete(asyncio.wait([
self.loop.create_task(t1()),
self.loop.create_task(t2()),
self.loop.create_task(t3()),
]))

0 comments on commit 780be2f

Please sign in to comment.