@@ -44,14 +44,14 @@ class UnitTestAPIAdapter(APIAdapter):
44
44
and pickle files to store data, so that data can be shared between processes.
45
45
"""
46
46
47
- mp_lock = Lock ()
47
+ lock = Lock ()
48
48
49
49
def __init__ (self ):
50
50
super ().__init__ ()
51
51
# Safely initialise the pickle files
52
+ UnitTestAPIAdapter .lock .acquire ()
52
53
if not os .path .exists (_PICKLE_DIRECTORY ):
53
54
os .makedirs (_PICKLE_DIRECTORY )
54
- UnitTestAPIAdapter .mp_lock .acquire ()
55
55
for file in [
56
56
_WORKFLOW_PICKLE_FILE ,
57
57
_RUNNING_WORKFLOW_PICKLE_FILE ,
@@ -61,10 +61,10 @@ def __init__(self):
61
61
]:
62
62
with open (file , "wb" ) as pickle_file :
63
63
Pickler (pickle_file ).dump ({})
64
- UnitTestAPIAdapter .mp_lock .release ()
64
+ UnitTestAPIAdapter .lock .release ()
65
65
66
66
def create_workflow (self , * , workflow_definition : Dict [str , Any ]) -> str :
67
- UnitTestAPIAdapter .mp_lock .acquire ()
67
+ UnitTestAPIAdapter .lock .acquire ()
68
68
with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
69
69
workflow = Unpickler (pickle_file ).load ()
70
70
@@ -74,23 +74,23 @@ def create_workflow(self, *, workflow_definition: Dict[str, Any]) -> str:
74
74
75
75
with open (_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
76
76
Pickler (pickle_file ).dump (workflow )
77
- UnitTestAPIAdapter .mp_lock .release ()
77
+ UnitTestAPIAdapter .lock .release ()
78
78
79
79
return {"id" : workflow_definition_id }
80
80
81
81
def get_workflow (self , * , workflow_id : str ) -> Dict [str , Any ]:
82
- UnitTestAPIAdapter .mp_lock .acquire ()
82
+ UnitTestAPIAdapter .lock .acquire ()
83
83
with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
84
84
workflow = Unpickler (pickle_file ).load ()
85
- UnitTestAPIAdapter .mp_lock .release ()
85
+ UnitTestAPIAdapter .lock .release ()
86
86
87
87
return {"workflow" : workflow [workflow_id ]} if workflow_id in workflow else {}
88
88
89
89
def get_workflow_by_name (self , * , name : str , version : str ) -> Dict [str , Any ]:
90
- UnitTestAPIAdapter .mp_lock .acquire ()
90
+ UnitTestAPIAdapter .lock .acquire ()
91
91
with open (_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
92
92
workflow = Unpickler (pickle_file ).load ()
93
- UnitTestAPIAdapter .mp_lock .release ()
93
+ UnitTestAPIAdapter .lock .release ()
94
94
95
95
item = {}
96
96
for wfid , value in workflow .items ():
@@ -99,7 +99,7 @@ def get_workflow_by_name(self, *, name: str, version: str) -> Dict[str, Any]:
99
99
return item
100
100
101
101
def create_running_workflow (self , * , workflow_id : str ) -> str :
102
- UnitTestAPIAdapter .mp_lock .acquire ()
102
+ UnitTestAPIAdapter .lock .acquire ()
103
103
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
104
104
running_workflow = Unpickler (pickle_file ).load ()
105
105
@@ -110,14 +110,14 @@ def create_running_workflow(self, *, workflow_id: str) -> str:
110
110
111
111
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
112
112
Pickler (pickle_file ).dump (running_workflow )
113
- UnitTestAPIAdapter .mp_lock .release ()
113
+ UnitTestAPIAdapter .lock .release ()
114
114
115
115
return {"id" : running_workflow_id }
116
116
117
117
def set_running_workflow_done (
118
118
self , * , running_workflow_id : str , success : bool
119
119
) -> None :
120
- UnitTestAPIAdapter .mp_lock .acquire ()
120
+ UnitTestAPIAdapter .lock .acquire ()
121
121
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
122
122
running_workflow = Unpickler (pickle_file ).load ()
123
123
@@ -127,13 +127,13 @@ def set_running_workflow_done(
127
127
128
128
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "wb" ) as pickle_file :
129
129
Pickler (pickle_file ).dump (running_workflow )
130
- UnitTestAPIAdapter .mp_lock .release ()
130
+ UnitTestAPIAdapter .lock .release ()
131
131
132
132
def get_running_workflow (self , * , running_workflow_id : str ) -> Dict [str , Any ]:
133
- UnitTestAPIAdapter .mp_lock .acquire ()
133
+ UnitTestAPIAdapter .lock .acquire ()
134
134
with open (_RUNNING_WORKFLOW_PICKLE_FILE , "rb" ) as pickle_file :
135
135
running_workflow = Unpickler (pickle_file ).load ()
136
- UnitTestAPIAdapter .mp_lock .release ()
136
+ UnitTestAPIAdapter .lock .release ()
137
137
138
138
if running_workflow_id not in running_workflow :
139
139
return {}
@@ -142,7 +142,7 @@ def get_running_workflow(self, *, running_workflow_id: str) -> Dict[str, Any]:
142
142
def create_running_workflow_step (
143
143
self , * , running_workflow_id : str , step : str
144
144
) -> str :
145
- UnitTestAPIAdapter .mp_lock .acquire ()
145
+ UnitTestAPIAdapter .lock .acquire ()
146
146
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
147
147
running_workflow_step = Unpickler (pickle_file ).load ()
148
148
@@ -160,17 +160,17 @@ def create_running_workflow_step(
160
160
161
161
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "wb" ) as pickle_file :
162
162
Pickler (pickle_file ).dump (running_workflow_step )
163
- UnitTestAPIAdapter .mp_lock .release ()
163
+ UnitTestAPIAdapter .lock .release ()
164
164
165
165
return {"id" : running_workflow_step_id }
166
166
167
167
def get_running_workflow_step (
168
168
self , * , running_workflow_step_id : str
169
169
) -> Dict [str , Any ]:
170
- UnitTestAPIAdapter .mp_lock .acquire ()
170
+ UnitTestAPIAdapter .lock .acquire ()
171
171
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
172
172
running_workflow_step = Unpickler (pickle_file ).load ()
173
- UnitTestAPIAdapter .mp_lock .release ()
173
+ UnitTestAPIAdapter .lock .release ()
174
174
175
175
if running_workflow_step_id not in running_workflow_step :
176
176
return {}
@@ -181,7 +181,7 @@ def get_running_workflow_step(
181
181
def set_running_workflow_step_done (
182
182
self , * , running_workflow_step_id : str , success : bool
183
183
) -> None :
184
- UnitTestAPIAdapter .mp_lock .acquire ()
184
+ UnitTestAPIAdapter .lock .acquire ()
185
185
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
186
186
running_workflow_step = Unpickler (pickle_file ).load ()
187
187
@@ -191,15 +191,15 @@ def set_running_workflow_step_done(
191
191
192
192
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "wb" ) as pickle_file :
193
193
Pickler (pickle_file ).dump (running_workflow_step )
194
- UnitTestAPIAdapter .mp_lock .release ()
194
+ UnitTestAPIAdapter .lock .release ()
195
195
196
196
def get_running_workflow_steps (
197
197
self , * , running_workflow_id : str
198
198
) -> List [Dict [str , Any ]]:
199
- UnitTestAPIAdapter .mp_lock .acquire ()
199
+ UnitTestAPIAdapter .lock .acquire ()
200
200
with open (_RUNNING_WORKFLOW_STEP_PICKLE_FILE , "rb" ) as pickle_file :
201
201
running_workflow_step = Unpickler (pickle_file ).load ()
202
- UnitTestAPIAdapter .mp_lock .release ()
202
+ UnitTestAPIAdapter .lock .release ()
203
203
204
204
steps = []
205
205
for key , value in running_workflow_step .items ():
@@ -209,7 +209,7 @@ def get_running_workflow_steps(
209
209
return {"count" : len (steps ), "running_workflow_steps" : steps }
210
210
211
211
def create_instance (self , * , running_workflow_step_id : str ) -> Dict [str , Any ]:
212
- UnitTestAPIAdapter .mp_lock .acquire ()
212
+ UnitTestAPIAdapter .lock .acquire ()
213
213
with open (_INSTANCE_PICKLE_FILE , "rb" ) as pickle_file :
214
214
instances = Unpickler (pickle_file ).load ()
215
215
@@ -222,20 +222,20 @@ def create_instance(self, *, running_workflow_step_id: str) -> Dict[str, Any]:
222
222
223
223
with open (_INSTANCE_PICKLE_FILE , "wb" ) as pickle_file :
224
224
Pickler (pickle_file ).dump (instances )
225
- UnitTestAPIAdapter .mp_lock .release ()
225
+ UnitTestAPIAdapter .lock .release ()
226
226
227
227
return {"id" : instance_id }
228
228
229
229
def get_instance (self , * , instance_id : str ) -> Dict [str , Any ]:
230
- UnitTestAPIAdapter .mp_lock .acquire ()
230
+ UnitTestAPIAdapter .lock .acquire ()
231
231
with open (_INSTANCE_PICKLE_FILE , "rb" ) as pickle_file :
232
232
instances = Unpickler (pickle_file ).load ()
233
- UnitTestAPIAdapter .mp_lock .release ()
233
+ UnitTestAPIAdapter .lock .release ()
234
234
235
235
return {} if instance_id not in instances else instances [instance_id ]
236
236
237
237
def create_task (self , * , instance_id : str ) -> Dict [str , Any ]:
238
- UnitTestAPIAdapter .mp_lock .acquire ()
238
+ UnitTestAPIAdapter .lock .acquire ()
239
239
with open (_TASK_PICKLE_FILE , "rb" ) as pickle_file :
240
240
tasks = Unpickler (pickle_file ).load ()
241
241
@@ -249,15 +249,15 @@ def create_task(self, *, instance_id: str) -> Dict[str, Any]:
249
249
250
250
with open (_TASK_PICKLE_FILE , "wb" ) as pickle_file :
251
251
Pickler (pickle_file ).dump (tasks )
252
- UnitTestAPIAdapter .mp_lock .release ()
252
+ UnitTestAPIAdapter .lock .release ()
253
253
254
254
return {"id" : task_id }
255
255
256
256
def get_task (self , * , task_id : str ) -> Dict [str , Any ]:
257
- UnitTestAPIAdapter .mp_lock .acquire ()
257
+ UnitTestAPIAdapter .lock .acquire ()
258
258
with open (_TASK_PICKLE_FILE , "rb" ) as pickle_file :
259
259
tasks = Unpickler (pickle_file ).load ()
260
- UnitTestAPIAdapter .mp_lock .release ()
260
+ UnitTestAPIAdapter .lock .release ()
261
261
262
262
return {} if task_id not in tasks else tasks [task_id ]
263
263
0 commit comments