Skip to content

Commit df73518

Browse files
author
Alan Christie
committed
fix: Minor tweak
1 parent 94d2a58 commit df73518

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

tests/api_adapter.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ class UnitTestAPIAdapter(APIAdapter):
4444
and pickle files to store data, so that data can be shared between processes.
4545
"""
4646

47-
mp_lock = Lock()
47+
lock = Lock()
4848

4949
def __init__(self):
5050
super().__init__()
5151
# Safely initialise the pickle files
52+
UnitTestAPIAdapter.lock.acquire()
5253
if not os.path.exists(_PICKLE_DIRECTORY):
5354
os.makedirs(_PICKLE_DIRECTORY)
54-
UnitTestAPIAdapter.mp_lock.acquire()
5555
for file in [
5656
_WORKFLOW_PICKLE_FILE,
5757
_RUNNING_WORKFLOW_PICKLE_FILE,
@@ -61,10 +61,10 @@ def __init__(self):
6161
]:
6262
with open(file, "wb") as pickle_file:
6363
Pickler(pickle_file).dump({})
64-
UnitTestAPIAdapter.mp_lock.release()
64+
UnitTestAPIAdapter.lock.release()
6565

6666
def create_workflow(self, *, workflow_definition: Dict[str, Any]) -> str:
67-
UnitTestAPIAdapter.mp_lock.acquire()
67+
UnitTestAPIAdapter.lock.acquire()
6868
with open(_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
6969
workflow = Unpickler(pickle_file).load()
7070

@@ -74,23 +74,23 @@ def create_workflow(self, *, workflow_definition: Dict[str, Any]) -> str:
7474

7575
with open(_WORKFLOW_PICKLE_FILE, "wb") as pickle_file:
7676
Pickler(pickle_file).dump(workflow)
77-
UnitTestAPIAdapter.mp_lock.release()
77+
UnitTestAPIAdapter.lock.release()
7878

7979
return {"id": workflow_definition_id}
8080

8181
def get_workflow(self, *, workflow_id: str) -> Dict[str, Any]:
82-
UnitTestAPIAdapter.mp_lock.acquire()
82+
UnitTestAPIAdapter.lock.acquire()
8383
with open(_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
8484
workflow = Unpickler(pickle_file).load()
85-
UnitTestAPIAdapter.mp_lock.release()
85+
UnitTestAPIAdapter.lock.release()
8686

8787
return {"workflow": workflow[workflow_id]} if workflow_id in workflow else {}
8888

8989
def get_workflow_by_name(self, *, name: str, version: str) -> Dict[str, Any]:
90-
UnitTestAPIAdapter.mp_lock.acquire()
90+
UnitTestAPIAdapter.lock.acquire()
9191
with open(_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
9292
workflow = Unpickler(pickle_file).load()
93-
UnitTestAPIAdapter.mp_lock.release()
93+
UnitTestAPIAdapter.lock.release()
9494

9595
item = {}
9696
for wfid, value in workflow.items():
@@ -99,7 +99,7 @@ def get_workflow_by_name(self, *, name: str, version: str) -> Dict[str, Any]:
9999
return item
100100

101101
def create_running_workflow(self, *, workflow_id: str) -> str:
102-
UnitTestAPIAdapter.mp_lock.acquire()
102+
UnitTestAPIAdapter.lock.acquire()
103103
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
104104
running_workflow = Unpickler(pickle_file).load()
105105

@@ -110,14 +110,14 @@ def create_running_workflow(self, *, workflow_id: str) -> str:
110110

111111
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "wb") as pickle_file:
112112
Pickler(pickle_file).dump(running_workflow)
113-
UnitTestAPIAdapter.mp_lock.release()
113+
UnitTestAPIAdapter.lock.release()
114114

115115
return {"id": running_workflow_id}
116116

117117
def set_running_workflow_done(
118118
self, *, running_workflow_id: str, success: bool
119119
) -> None:
120-
UnitTestAPIAdapter.mp_lock.acquire()
120+
UnitTestAPIAdapter.lock.acquire()
121121
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
122122
running_workflow = Unpickler(pickle_file).load()
123123

@@ -127,13 +127,13 @@ def set_running_workflow_done(
127127

128128
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "wb") as pickle_file:
129129
Pickler(pickle_file).dump(running_workflow)
130-
UnitTestAPIAdapter.mp_lock.release()
130+
UnitTestAPIAdapter.lock.release()
131131

132132
def get_running_workflow(self, *, running_workflow_id: str) -> Dict[str, Any]:
133-
UnitTestAPIAdapter.mp_lock.acquire()
133+
UnitTestAPIAdapter.lock.acquire()
134134
with open(_RUNNING_WORKFLOW_PICKLE_FILE, "rb") as pickle_file:
135135
running_workflow = Unpickler(pickle_file).load()
136-
UnitTestAPIAdapter.mp_lock.release()
136+
UnitTestAPIAdapter.lock.release()
137137

138138
if running_workflow_id not in running_workflow:
139139
return {}
@@ -142,7 +142,7 @@ def get_running_workflow(self, *, running_workflow_id: str) -> Dict[str, Any]:
142142
def create_running_workflow_step(
143143
self, *, running_workflow_id: str, step: str
144144
) -> str:
145-
UnitTestAPIAdapter.mp_lock.acquire()
145+
UnitTestAPIAdapter.lock.acquire()
146146
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
147147
running_workflow_step = Unpickler(pickle_file).load()
148148

@@ -160,17 +160,17 @@ def create_running_workflow_step(
160160

161161
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "wb") as pickle_file:
162162
Pickler(pickle_file).dump(running_workflow_step)
163-
UnitTestAPIAdapter.mp_lock.release()
163+
UnitTestAPIAdapter.lock.release()
164164

165165
return {"id": running_workflow_step_id}
166166

167167
def get_running_workflow_step(
168168
self, *, running_workflow_step_id: str
169169
) -> Dict[str, Any]:
170-
UnitTestAPIAdapter.mp_lock.acquire()
170+
UnitTestAPIAdapter.lock.acquire()
171171
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
172172
running_workflow_step = Unpickler(pickle_file).load()
173-
UnitTestAPIAdapter.mp_lock.release()
173+
UnitTestAPIAdapter.lock.release()
174174

175175
if running_workflow_step_id not in running_workflow_step:
176176
return {}
@@ -181,7 +181,7 @@ def get_running_workflow_step(
181181
def set_running_workflow_step_done(
182182
self, *, running_workflow_step_id: str, success: bool
183183
) -> None:
184-
UnitTestAPIAdapter.mp_lock.acquire()
184+
UnitTestAPIAdapter.lock.acquire()
185185
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
186186
running_workflow_step = Unpickler(pickle_file).load()
187187

@@ -191,15 +191,15 @@ def set_running_workflow_step_done(
191191

192192
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "wb") as pickle_file:
193193
Pickler(pickle_file).dump(running_workflow_step)
194-
UnitTestAPIAdapter.mp_lock.release()
194+
UnitTestAPIAdapter.lock.release()
195195

196196
def get_running_workflow_steps(
197197
self, *, running_workflow_id: str
198198
) -> List[Dict[str, Any]]:
199-
UnitTestAPIAdapter.mp_lock.acquire()
199+
UnitTestAPIAdapter.lock.acquire()
200200
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
201201
running_workflow_step = Unpickler(pickle_file).load()
202-
UnitTestAPIAdapter.mp_lock.release()
202+
UnitTestAPIAdapter.lock.release()
203203

204204
steps = []
205205
for key, value in running_workflow_step.items():
@@ -209,7 +209,7 @@ def get_running_workflow_steps(
209209
return {"count": len(steps), "running_workflow_steps": steps}
210210

211211
def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
212-
UnitTestAPIAdapter.mp_lock.acquire()
212+
UnitTestAPIAdapter.lock.acquire()
213213
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
214214
instances = Unpickler(pickle_file).load()
215215

@@ -222,20 +222,20 @@ def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
222222

223223
with open(_INSTANCE_PICKLE_FILE, "wb") as pickle_file:
224224
Pickler(pickle_file).dump(instances)
225-
UnitTestAPIAdapter.mp_lock.release()
225+
UnitTestAPIAdapter.lock.release()
226226

227227
return {"id": instance_id}
228228

229229
def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
230-
UnitTestAPIAdapter.mp_lock.acquire()
230+
UnitTestAPIAdapter.lock.acquire()
231231
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
232232
instances = Unpickler(pickle_file).load()
233-
UnitTestAPIAdapter.mp_lock.release()
233+
UnitTestAPIAdapter.lock.release()
234234

235235
return {} if instance_id not in instances else instances[instance_id]
236236

237237
def create_task(self, *, instance_id: str) -> Dict[str, Any]:
238-
UnitTestAPIAdapter.mp_lock.acquire()
238+
UnitTestAPIAdapter.lock.acquire()
239239
with open(_TASK_PICKLE_FILE, "rb") as pickle_file:
240240
tasks = Unpickler(pickle_file).load()
241241

@@ -249,15 +249,15 @@ def create_task(self, *, instance_id: str) -> Dict[str, Any]:
249249

250250
with open(_TASK_PICKLE_FILE, "wb") as pickle_file:
251251
Pickler(pickle_file).dump(tasks)
252-
UnitTestAPIAdapter.mp_lock.release()
252+
UnitTestAPIAdapter.lock.release()
253253

254254
return {"id": task_id}
255255

256256
def get_task(self, *, task_id: str) -> Dict[str, Any]:
257-
UnitTestAPIAdapter.mp_lock.acquire()
257+
UnitTestAPIAdapter.lock.acquire()
258258
with open(_TASK_PICKLE_FILE, "rb") as pickle_file:
259259
tasks = Unpickler(pickle_file).load()
260-
UnitTestAPIAdapter.mp_lock.release()
260+
UnitTestAPIAdapter.lock.release()
261261

262262
return {} if task_id not in tasks else tasks[task_id]
263263

0 commit comments

Comments
 (0)