13
13
14
14
15
15
16
- def test_context_manager_thread_safety (tmp_path ):
16
+ def create_many_threads (tmp_path ):
17
17
autosave .configure (tmp_path , DEVICE_NAME )
18
18
in_cm_event = threading .Event ()
19
19
@@ -31,3 +31,219 @@ def create_pv_in_thread(name):
31
31
in_cm_event .set ()
32
32
builder .aOut ("PV-FROM-CM" )
33
33
[x .join () for x in threads ]
34
+
35
+ def original_test_1 (tmp_path ):
36
+ autosave .configure (tmp_path , DEVICE_NAME )
37
+ in_cm_event = threading .Event ()
38
+
39
+ def create_pv_in_thread (name ):
40
+ in_cm_event .wait ()
41
+ builder .aOut (name , autosave = False )
42
+ pv_thread_before_cm = threading .Thread (
43
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
44
+ pv_thread_in_cm = threading .Thread (
45
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
46
+ pv_thread_before_cm .start ()
47
+ with autosave .Autosave (["VAL" , "EGU" ]):
48
+ in_cm_event .set ()
49
+ builder .aOut ("PV-FROM-CM" )
50
+ pv_thread_in_cm .start ()
51
+ pv_thread_in_cm .join ()
52
+ pv_thread_before_cm .join ()
53
+
54
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
55
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
56
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
57
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
58
+
59
+ def original_test_2 (tmp_path ):
60
+ autosave .configure (tmp_path , DEVICE_NAME )
61
+ in_cm_event = threading .Event ()
62
+
63
+ def create_pv_in_thread (name ):
64
+ in_cm_event .wait ()
65
+ builder .aOut (name , autosave = False )
66
+ pv_thread_before_cm = threading .Thread (
67
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
68
+ pv_thread_in_cm = threading .Thread (
69
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
70
+ pv_thread_before_cm .start ()
71
+ with autosave .Autosave (["VAL" , "EGU" ]):
72
+ in_cm_event .set ()
73
+ builder .aOut ("PV-FROM-CM" )
74
+ pv_thread_in_cm .start ()
75
+ pv_thread_in_cm .join ()
76
+ pv_thread_before_cm .join ()
77
+
78
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
79
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
80
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
81
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
82
+
83
+ def original_test_3 (tmp_path ):
84
+ autosave .configure (tmp_path , DEVICE_NAME )
85
+ in_cm_event = threading .Event ()
86
+
87
+ def create_pv_in_thread (name ):
88
+ in_cm_event .wait ()
89
+ builder .aOut (name , autosave = False )
90
+ pv_thread_before_cm = threading .Thread (
91
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
92
+ pv_thread_in_cm = threading .Thread (
93
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
94
+ pv_thread_before_cm .start ()
95
+ with autosave .Autosave (["VAL" , "EGU" ]):
96
+ in_cm_event .set ()
97
+ builder .aOut ("PV-FROM-CM" )
98
+ pv_thread_in_cm .start ()
99
+ pv_thread_in_cm .join ()
100
+ pv_thread_before_cm .join ()
101
+
102
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
103
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
104
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
105
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
106
+
107
+ def original_test_4 (tmp_path ):
108
+ autosave .configure (tmp_path , DEVICE_NAME )
109
+ in_cm_event = threading .Event ()
110
+
111
+ def create_pv_in_thread (name ):
112
+ in_cm_event .wait ()
113
+ builder .aOut (name , autosave = False )
114
+ pv_thread_before_cm = threading .Thread (
115
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
116
+ pv_thread_in_cm = threading .Thread (
117
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
118
+ pv_thread_before_cm .start ()
119
+ with autosave .Autosave (["VAL" , "EGU" ]):
120
+ in_cm_event .set ()
121
+ builder .aOut ("PV-FROM-CM" )
122
+ pv_thread_in_cm .start ()
123
+ pv_thread_in_cm .join ()
124
+ pv_thread_before_cm .join ()
125
+
126
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
127
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
128
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
129
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
130
+
131
+ def original_test_5 (tmp_path ):
132
+ autosave .configure (tmp_path , DEVICE_NAME )
133
+ in_cm_event = threading .Event ()
134
+
135
+ def create_pv_in_thread (name ):
136
+ in_cm_event .wait ()
137
+ builder .aOut (name , autosave = False )
138
+ pv_thread_before_cm = threading .Thread (
139
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
140
+ pv_thread_in_cm = threading .Thread (
141
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
142
+ pv_thread_before_cm .start ()
143
+ with autosave .Autosave (["VAL" , "EGU" ]):
144
+ in_cm_event .set ()
145
+ builder .aOut ("PV-FROM-CM" )
146
+ pv_thread_in_cm .start ()
147
+ pv_thread_in_cm .join ()
148
+ pv_thread_before_cm .join ()
149
+
150
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
151
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
152
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
153
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
154
+
155
+ def original_test_6 (tmp_path ):
156
+ autosave .configure (tmp_path , DEVICE_NAME )
157
+ in_cm_event = threading .Event ()
158
+
159
+ def create_pv_in_thread (name ):
160
+ in_cm_event .wait ()
161
+ builder .aOut (name , autosave = False )
162
+ pv_thread_before_cm = threading .Thread (
163
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
164
+ pv_thread_in_cm = threading .Thread (
165
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
166
+ pv_thread_before_cm .start ()
167
+ with autosave .Autosave (["VAL" , "EGU" ]):
168
+ in_cm_event .set ()
169
+ builder .aOut ("PV-FROM-CM" )
170
+ pv_thread_in_cm .start ()
171
+ pv_thread_in_cm .join ()
172
+ pv_thread_before_cm .join ()
173
+
174
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
175
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
176
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
177
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
178
+
179
+ def original_test_7 (tmp_path ):
180
+ autosave .configure (tmp_path , DEVICE_NAME )
181
+ in_cm_event = threading .Event ()
182
+
183
+ def create_pv_in_thread (name ):
184
+ in_cm_event .wait ()
185
+ builder .aOut (name , autosave = False )
186
+ pv_thread_before_cm = threading .Thread (
187
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
188
+ pv_thread_in_cm = threading .Thread (
189
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
190
+ pv_thread_before_cm .start ()
191
+ with autosave .Autosave (["VAL" , "EGU" ]):
192
+ in_cm_event .set ()
193
+ builder .aOut ("PV-FROM-CM" )
194
+ pv_thread_in_cm .start ()
195
+ pv_thread_in_cm .join ()
196
+ pv_thread_before_cm .join ()
197
+
198
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
199
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
200
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
201
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
202
+
203
+ def original_test_8 (tmp_path ):
204
+ autosave .configure (tmp_path , DEVICE_NAME )
205
+ in_cm_event = threading .Event ()
206
+
207
+ def create_pv_in_thread (name ):
208
+ in_cm_event .wait ()
209
+ builder .aOut (name , autosave = False )
210
+ pv_thread_before_cm = threading .Thread (
211
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
212
+ pv_thread_in_cm = threading .Thread (
213
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
214
+ pv_thread_before_cm .start ()
215
+ with autosave .Autosave (["VAL" , "EGU" ]):
216
+ in_cm_event .set ()
217
+ builder .aOut ("PV-FROM-CM" )
218
+ pv_thread_in_cm .start ()
219
+ pv_thread_in_cm .join ()
220
+ pv_thread_before_cm .join ()
221
+
222
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
223
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
224
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
225
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
226
+
227
+ def original_test_9 (tmp_path ):
228
+ autosave .configure (tmp_path , DEVICE_NAME )
229
+ in_cm_event = threading .Event ()
230
+
231
+ def create_pv_in_thread (name ):
232
+ in_cm_event .wait ()
233
+ builder .aOut (name , autosave = False )
234
+ pv_thread_before_cm = threading .Thread (
235
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-BEFORE" ])
236
+ pv_thread_in_cm = threading .Thread (
237
+ target = create_pv_in_thread , args = ["PV-FROM-THREAD-DURING" ])
238
+ pv_thread_before_cm .start ()
239
+ with autosave .Autosave (["VAL" , "EGU" ]):
240
+ in_cm_event .set ()
241
+ builder .aOut ("PV-FROM-CM" )
242
+ pv_thread_in_cm .start ()
243
+ pv_thread_in_cm .join ()
244
+ pv_thread_before_cm .join ()
245
+
246
+ assert "PV-FROM-THREAD-BEFORE" not in autosave .Autosave ._pvs
247
+ assert "PV-FROM-THREAD-DURING" not in autosave .Autosave ._pvs
248
+ assert device_core .LookupRecord ("PV-FROM-THREAD-BEFORE" )
249
+ assert device_core .LookupRecord ("PV-FROM-THREAD-DURING" )
0 commit comments