1
- # pylint: disable=broad-except
1
+ # pylint: disable=broad-except, too-many-arguments
2
2
import threading
3
3
import time
4
4
import traceback
@@ -75,15 +75,15 @@ class MyException(Exception):
75
75
assert rows == []
76
76
77
77
78
- def try_to_allocate (orderid , sku , exceptions ):
78
+ def try_to_allocate (orderid , sku , exceptions , session_factory ):
79
79
line = model .OrderLine (orderid , sku , 10 )
80
80
try :
81
- with unit_of_work .SqlAlchemyUnitOfWork () as uow :
81
+ with unit_of_work .SqlAlchemyUnitOfWork (session_factory ) as uow :
82
82
product = uow .products .get (sku = sku )
83
83
product .allocate (line )
84
84
time .sleep (0.2 )
85
85
uow .commit ()
86
- except Exception as e :
86
+ except Exception as e : # pylint: disable=broad-except
87
87
print (traceback .format_exc ())
88
88
exceptions .append (e )
89
89
@@ -96,8 +96,12 @@ def test_concurrent_updates_to_version_are_not_allowed(postgres_session_factory)
96
96
97
97
order1 , order2 = random_orderid (1 ), random_orderid (2 )
98
98
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
+ )
101
105
thread1 = threading .Thread (target = try_to_allocate_order1 )
102
106
thread2 = threading .Thread (target = try_to_allocate_order2 )
103
107
thread1 .start ()
@@ -121,5 +125,5 @@ def test_concurrent_updates_to_version_are_not_allowed(postgres_session_factory)
121
125
dict (sku = sku ),
122
126
))
123
127
assert len (orders ) == 1
124
- with unit_of_work .SqlAlchemyUnitOfWork () as uow :
128
+ with unit_of_work .SqlAlchemyUnitOfWork (postgres_session_factory ) as uow :
125
129
uow .session .execute ('select 1' )
0 commit comments