1
+ import contextlib
1
2
import typing
3
+ import uuid
2
4
import pytest
3
5
import simvue
4
6
import time
8
10
import os
9
11
import multiprocessing
10
12
import multiprocessing .synchronize
11
-
13
+
14
+ from simvue .api .objects .folder import Folder
15
+ from simvue .exception import ObjectNotFoundError
16
+
12
17
13
18
@pytest .mark .executor
14
19
@pytest .mark .parametrize ("successful" , (True , False ), ids = ("successful" , "failing" ))
@@ -18,6 +23,9 @@ def test_executor_add_process(
18
23
) -> None :
19
24
import logging
20
25
trigger = multiprocessing .Event ()
26
+ folder_id = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
27
+ folder = Folder .new (path = f"/simvue_unit_testing/{ folder_id } " )
28
+ folder .commit ()
21
29
22
30
def completion_callback (* _ , trigger = trigger , ** __ ):
23
31
trigger .set ()
@@ -26,7 +34,8 @@ def completion_callback(*_, trigger=trigger, **__):
26
34
run .init (
27
35
f"test_executor_{ 'success' if successful else 'fail' } " ,
28
36
tags = ["simvue_client_unit_tests" , request .node .name .replace ("[" , "_" ).replace ("]" , "_" )],
29
- folder = "/simvue_unit_testing"
37
+ folder = f"/simvue_unit_testing/{ folder_id } " ,
38
+ retention_period = "2 mins"
30
39
)
31
40
run .add_process (
32
41
identifier = f"test_add_process_{ 'success' if successful else 'fail' } " ,
@@ -44,18 +53,24 @@ def completion_callback(*_, trigger=trigger, **__):
44
53
with pytest .raises (SystemExit ):
45
54
run .close ()
46
55
56
+ with contextlib .suppress (ObjectNotFoundError ):
57
+ folder .delete (recursive = True , delete_runs = True )
58
+
47
59
48
60
@pytest .mark .executor
49
61
@pytest .mark .unix
50
62
def test_executor_multiprocess (request : pytest .FixtureRequest ) -> None :
51
63
triggers : dict [int , multiprocessing .synchronize .Event ] = {}
52
64
callbacks : dict [int , typing .Callable ] = {}
53
65
events : dict [int , bool ] = {}
66
+ folder_id = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
67
+ folder = Folder .new (path = f"/simvue_unit_testing/{ folder_id } " )
68
+ folder .commit ()
54
69
with tempfile .TemporaryDirectory () as tempd :
55
70
with simvue .Run () as run :
56
71
run .init (
57
72
"test_executor_multiprocess" ,
58
- folder = "/simvue_unit_testing" ,
73
+ folder = f "/simvue_unit_testing/ { folder_id } " ,
59
74
tags = ["simvue_client_tests" , request .node .name ]
60
75
)
61
76
@@ -82,10 +97,15 @@ def callback(*_, evts=events, ident=i, **__):
82
97
for i in range (10 ):
83
98
os .remove (f"test_executor_multiprocess_cmd_{ i } .err" )
84
99
os .remove (f"test_executor_multiprocess_cmd_{ i } .out" )
100
+ with contextlib .suppress (ObjectNotFoundError ):
101
+ folder .delete (recursive = True , delete_runs = True )
85
102
86
103
87
104
@pytest .mark .executor
88
105
def test_add_process_command_assembly (request : pytest .FixtureRequest ) -> None :
106
+ folder_id = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
107
+ folder = Folder .new (path = f"/simvue_unit_testing/{ folder_id } " )
108
+ folder .commit ()
89
109
with tempfile .TemporaryDirectory () as tempd :
90
110
_python_script = """
91
111
import argparse
@@ -115,7 +135,7 @@ def test_add_process_command_assembly(request: pytest.FixtureRequest) -> None:
115
135
with simvue .Run () as run :
116
136
run .init (
117
137
"test_advanced_executor" ,
118
- folder = "/simvue_unit_testing" ,
138
+ folder = f "/simvue_unit_testing/ { folder_id } " ,
119
139
tags = ["simvue_client_tests" , request .node .name ]
120
140
)
121
141
run .add_process (
@@ -126,17 +146,22 @@ def test_add_process_command_assembly(request: pytest.FixtureRequest) -> None:
126
146
output_file = out_file
127
147
)
128
148
assert run ._executor .command_str [exe_id ] == expected_cmd
149
+ with contextlib .suppress (ObjectNotFoundError ):
150
+ folder .delete (recursive = True , delete_runs = True )
129
151
130
152
@pytest .mark .executor
131
153
def test_completion_callbacks_var_change (request : pytest .FixtureRequest ) -> None :
132
154
success : dict [str , bool ] = {"complete" : False }
133
155
def completion_callback (* _ , success : dict [str , bool ]= success , ** __ ):
134
156
success ["complete" ] = True
157
+ folder_id = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
158
+ folder = Folder .new (path = f"/simvue_unit_testing/{ folder_id } " )
159
+ folder .commit ()
135
160
136
161
with simvue .Run () as run :
137
162
run .init (
138
163
"test_completion_callbacks_var_change" ,
139
- folder = "/simvue_unit_testing" ,
164
+ folder = f "/simvue_unit_testing/ { folder_id } " ,
140
165
tags = ["simvue_client_tests" , request .node .name ]
141
166
)
142
167
run .add_process (
@@ -150,16 +175,21 @@ def completion_callback(*_, success: dict[str, bool]=success, **__):
150
175
time .sleep (1 )
151
176
152
177
assert success ["complete" ]
178
+ with contextlib .suppress (ObjectNotFoundError ):
179
+ folder .delete (recursive = True , delete_runs = True )
153
180
154
181
@pytest .mark .executor
155
182
@pytest .mark .unix
156
183
def test_completion_trigger_set (request : pytest .FixtureRequest ) -> None :
157
184
trigger = multiprocessing .Event ()
185
+ folder_id = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
186
+ folder = Folder .new (path = f"/simvue_unit_testing/{ folder_id } " )
187
+ folder .commit ()
158
188
159
189
with simvue .Run () as run :
160
190
run .init (
161
191
"test_completion_trigger_set" ,
162
- folder = "/simvue_unit_testing" ,
192
+ folder = f "/simvue_unit_testing/ { folder_id } " ,
163
193
tags = ["simvue_client_tests" , request .node .name ]
164
194
)
165
195
run .add_process (
@@ -173,6 +203,8 @@ def test_completion_trigger_set(request: pytest.FixtureRequest) -> None:
173
203
time .sleep (1 )
174
204
175
205
assert trigger .is_set ()
206
+ with contextlib .suppress (ObjectNotFoundError ):
207
+ folder .delete (recursive = True , delete_runs = True )
176
208
177
209
@pytest .mark .executor
178
210
def test_completion_callbacks_trigger_set (request : pytest .FixtureRequest ) -> None :
@@ -181,6 +213,10 @@ def test_completion_callbacks_trigger_set(request: pytest.FixtureRequest) -> Non
181
213
def completion_callback (* _ , trigger = trigger , ** __ ):
182
214
trigger .set ()
183
215
216
+ folder_id = f"{ uuid .uuid4 ()} " .split ("-" )[0 ]
217
+ folder = Folder .new (path = f"/simvue_unit_testing/{ folder_id } " )
218
+ folder .commit ()
219
+
184
220
with simvue .Run () as run :
185
221
run .init (
186
222
"test_completion_callbacks_trigger_set" ,
@@ -198,4 +234,6 @@ def completion_callback(*_, trigger=trigger, **__):
198
234
time .sleep (1 )
199
235
200
236
assert trigger .is_set ()
237
+ with contextlib .suppress (ObjectNotFoundError ):
238
+ folder .delete (recursive = True , delete_runs = True )
201
239
0 commit comments