1- # pylint: disable=broad-except
1+ # pylint: disable=broad-except, too-many-arguments
22import threading
33import time
44import traceback
@@ -75,15 +75,15 @@ class MyException(Exception):
7575 assert rows == []
7676
7777
78- def try_to_allocate (orderid , sku , exceptions ):
78+ def try_to_allocate (orderid , sku , exceptions , session_factory ):
7979 line = model .OrderLine (orderid , sku , 10 )
8080 try :
81- with unit_of_work .SqlAlchemyUnitOfWork () as uow :
81+ with unit_of_work .SqlAlchemyUnitOfWork (session_factory ) as uow :
8282 product = uow .products .get (sku = sku )
8383 product .allocate (line )
8484 time .sleep (0.2 )
8585 uow .commit ()
86- except Exception as e :
86+ except Exception as e : # pylint: disable=broad-except
8787 print (traceback .format_exc ())
8888 exceptions .append (e )
8989
@@ -96,8 +96,12 @@ def test_concurrent_updates_to_version_are_not_allowed(postgres_session_factory)
9696
9797 order1 , order2 = random_orderid (1 ), random_orderid (2 )
9898 exceptions = [] # type: List[Exception]
99- try_to_allocate_order1 = lambda : try_to_allocate (order1 , sku , exceptions )
100- try_to_allocate_order2 = lambda : try_to_allocate (order2 , sku , exceptions )
99+ try_to_allocate_order1 = lambda : try_to_allocate (
100+ order1 , sku , exceptions , postgres_session_factory
101+ )
102+ try_to_allocate_order2 = lambda : try_to_allocate (
103+ order2 , sku , exceptions , postgres_session_factory
104+ )
101105 thread1 = threading .Thread (target = try_to_allocate_order1 )
102106 thread2 = threading .Thread (target = try_to_allocate_order2 )
103107 thread1 .start ()
@@ -121,5 +125,5 @@ def test_concurrent_updates_to_version_are_not_allowed(postgres_session_factory)
121125 dict (sku = sku ),
122126 ))
123127 assert len (orders ) == 1
124- with unit_of_work .SqlAlchemyUnitOfWork () as uow :
128+ with unit_of_work .SqlAlchemyUnitOfWork (postgres_session_factory ) as uow :
125129 uow .session .execute ('select 1' )
0 commit comments