15
15
_JOB_DEFINITIONS : Dict [str , Any ] = yaml .load (jd_file , Loader = yaml .FullLoader )
16
16
assert _JOB_DEFINITIONS
17
17
18
+ # Table UUID formats
18
19
_INSTANCE_ID_FORMAT : str = "instance-00000000-0000-0000-0000-{id:012d}"
19
20
_TASK_ID_FORMAT : str = "task-00000000-0000-0000-0000-{id:012d}"
20
21
_WORKFLOW_DEFINITION_ID_FORMAT : str = "workflow-00000000-0000-0000-0000-{id:012d}"
23
24
"r-workflow-step-00000000-0000-0000-0000-{id:012d}"
24
25
)
25
26
27
+ # Pickle files (representing each 'Table')
26
28
_WORKFLOW_PICKLE_FILE : str = "workflow.pickle"
27
29
_RUNNING_WORKFLOW_PICKLE_FILE : str = "running-workflow.pickle"
28
30
_RUNNING_WORKFLOW_STEP_PICKLE_FILE : str = "running-workflow-step.pickle"
33
35
class UnitTestAPIAdapter (APIAdapter ):
34
36
"""A minimal API adapter. It serves-up Job Definitions
35
37
from the job-definitions/job-definitions.yaml file and provides basic
36
- (in-memory) storage for Workflow Definitions and related tables."""
38
+ storage for Workflow Definitions and related tables.
39
+
40
+ Because the adapter is used by the multi-processing test suite, it uses both a lock
41
+ and pickle files to store data, so that data can be shared between processes.
42
+ """
37
43
38
44
mp_lock = Lock ()
39
45
@@ -74,9 +80,7 @@ def get_workflow(self, *, workflow_id: str) -> Dict[str, Any]:
74
80
workflow = Unpickler (pickle_file ).load ()
75
81
UnitTestAPIAdapter .mp_lock .release ()
76
82
77
- if workflow_id not in workflow :
78
- return {}
79
- return {"workflow" : workflow [workflow_id ]}
83
+ return {"workflow" : workflow [workflow_id ]} if workflow_id in workflow else {}
80
84
81
85
def get_workflow_by_name (self , * , name : str , version : str ) -> Dict [str , Any ]:
82
86
UnitTestAPIAdapter .mp_lock .acquire ()
@@ -224,9 +228,7 @@ def get_instance(self, *, instance_id: str) -> Dict[str, Any]:
224
228
instances = Unpickler (pickle_file ).load ()
225
229
UnitTestAPIAdapter .mp_lock .release ()
226
230
227
- if instance_id not in instances :
228
- return {}
229
- return instances [instance_id ]
231
+ return {} if instance_id not in instances else instances [instance_id ]
230
232
231
233
def create_task (self , * , instance_id : str ) -> Dict [str , Any ]:
232
234
UnitTestAPIAdapter .mp_lock .acquire ()
@@ -253,9 +255,7 @@ def get_task(self, *, task_id: str) -> Dict[str, Any]:
253
255
tasks = Unpickler (pickle_file ).load ()
254
256
UnitTestAPIAdapter .mp_lock .release ()
255
257
256
- if task_id not in tasks :
257
- return {}
258
- return tasks [task_id ]
258
+ return {} if task_id not in tasks else tasks [task_id ]
259
259
260
260
def get_job (
261
261
self , * , collection : str , job : str , version : str
0 commit comments