@@ -206,52 +206,55 @@ def play_with_lock() -> None:
206206 lock .acquire () # !ACQUIRE! test_lock_gevent_tasks
207207 lock .release () # !RELEASE! test_lock_gevent_tasks
208208
209+ def validate_and_cleanup ():
210+ ddup .upload ()
211+
212+ expected_filename = "test_threading.py"
213+ linenos = get_lock_linenos (test_name )
214+
215+ profile = pprof_utils .parse_newest_profile (output_filename )
216+ pprof_utils .assert_lock_events (
217+ profile ,
218+ expected_acquire_events = [
219+ pprof_utils .LockAcquireEvent (
220+ caller_name = "play_with_lock" ,
221+ filename = expected_filename ,
222+ linenos = linenos ,
223+ lock_name = "lock" ,
224+ # TODO: With stack_v2, the way we trace gevent greenlets has
225+ # changed, and we'd need to expose an API to get the task_id,
226+ # task_name, and task_frame.
227+ # task_id=t.ident,
228+ # task_name="foobar",
229+ ),
230+ ],
231+ expected_release_events = [
232+ pprof_utils .LockReleaseEvent (
233+ caller_name = "play_with_lock" ,
234+ filename = expected_filename ,
235+ linenos = linenos ,
236+ lock_name = "lock" ,
237+ # TODO: With stack_v2, the way we trace gevent greenlets has
238+ # changed, and we'd need to expose an API to get the task_id,
239+ # task_name, and task_frame.
240+ # task_id=t.ident,
241+ # task_name="foobar",
242+ ),
243+ ],
244+ )
245+
246+ for f in glob .glob (pprof_prefix + ".*" ):
247+ try :
248+ os .remove (f )
249+ except Exception as e :
250+ print ("Error removing file: {}" .format (e ))
251+
209252 with ThreadingLockCollector (capture_pct = 100 ):
210253 t = threading .Thread (name = "foobar" , target = play_with_lock )
211254 t .start ()
212255 t .join ()
213256
214- ddup .upload ()
215-
216- expected_filename = "test_threading.py"
217- linenos = get_lock_linenos (test_name )
218-
219- profile = pprof_utils .parse_newest_profile (output_filename )
220- pprof_utils .assert_lock_events (
221- profile ,
222- expected_acquire_events = [
223- pprof_utils .LockAcquireEvent (
224- caller_name = "play_with_lock" ,
225- filename = expected_filename ,
226- linenos = linenos ,
227- lock_name = "lock" ,
228- # TODO: With stack_v2, the way we trace gevent greenlets has
229- # changed, and we'd need to expose an API to get the task_id,
230- # task_name, and task_frame.
231- # task_id=t.ident,
232- # task_name="foobar",
233- ),
234- ],
235- expected_release_events = [
236- pprof_utils .LockReleaseEvent (
237- caller_name = "play_with_lock" ,
238- filename = expected_filename ,
239- linenos = linenos ,
240- lock_name = "lock" ,
241- # TODO: With stack_v2, the way we trace gevent greenlets has
242- # changed, and we'd need to expose an API to get the task_id,
243- # task_name, and task_frame.
244- # task_id=t.ident,
245- # task_name="foobar",
246- ),
247- ],
248- )
249-
250- for f in glob .glob (pprof_prefix + ".*" ):
251- try :
252- os .remove (f )
253- except Exception as e :
254- print ("Error removing file: {}" .format (e ))
257+ validate_and_cleanup ()
255258
256259
257260# This test has to be run in a subprocess because it calls gevent.monkey.patch_all()
@@ -291,52 +294,55 @@ def play_with_lock() -> None:
291294 lock .acquire () # !ACQUIRE! test_rlock_gevent_tasks
292295 lock .release () # !RELEASE! test_rlock_gevent_tasks
293296
297+ def validate_and_cleanup ():
298+ ddup .upload ()
299+
300+ expected_filename = "test_threading.py"
301+ linenos = get_lock_linenos (test_name )
302+
303+ profile = pprof_utils .parse_newest_profile (output_filename )
304+ pprof_utils .assert_lock_events (
305+ profile ,
306+ expected_acquire_events = [
307+ pprof_utils .LockAcquireEvent (
308+ caller_name = "play_with_lock" ,
309+ filename = expected_filename ,
310+ linenos = linenos ,
311+ lock_name = "lock" ,
312+ # TODO: With stack_v2, the way we trace gevent greenlets has
313+ # changed, and we'd need to expose an API to get the task_id,
314+ # task_name, and task_frame.
315+ # task_id=t.ident,
316+ # task_name="foobar",
317+ ),
318+ ],
319+ expected_release_events = [
320+ pprof_utils .LockReleaseEvent (
321+ caller_name = "play_with_lock" ,
322+ filename = expected_filename ,
323+ linenos = linenos ,
324+ lock_name = "lock" ,
325+ # TODO: With stack_v2, the way we trace gevent greenlets has
326+ # changed, and we'd need to expose an API to get the task_id,
327+ # task_name, and task_frame.
328+ # task_id=t.ident,
329+ # task_name="foobar",
330+ ),
331+ ],
332+ )
333+
334+ for f in glob .glob (pprof_prefix + ".*" ):
335+ try :
336+ os .remove (f )
337+ except Exception as e :
338+ print ("Error removing file: {}" .format (e ))
339+
294340 with ThreadingRLockCollector (capture_pct = 100 ):
295341 t = threading .Thread (name = "foobar" , target = play_with_lock )
296342 t .start ()
297343 t .join ()
298344
299- ddup .upload ()
300-
301- expected_filename = "test_threading.py"
302- linenos = get_lock_linenos (test_name )
303-
304- profile = pprof_utils .parse_newest_profile (output_filename )
305- pprof_utils .assert_lock_events (
306- profile ,
307- expected_acquire_events = [
308- pprof_utils .LockAcquireEvent (
309- caller_name = "play_with_lock" ,
310- filename = expected_filename ,
311- linenos = linenos ,
312- lock_name = "lock" ,
313- # TODO: With stack_v2, the way we trace gevent greenlets has
314- # changed, and we'd need to expose an API to get the task_id,
315- # task_name, and task_frame.
316- # task_id=t.ident,
317- # task_name="foobar",
318- ),
319- ],
320- expected_release_events = [
321- pprof_utils .LockReleaseEvent (
322- caller_name = "play_with_lock" ,
323- filename = expected_filename ,
324- linenos = linenos ,
325- lock_name = "lock" ,
326- # TODO: With stack_v2, the way we trace gevent greenlets has
327- # changed, and we'd need to expose an API to get the task_id,
328- # task_name, and task_frame.
329- # task_id=t.ident,
330- # task_name="foobar",
331- ),
332- ],
333- )
334-
335- for f in glob .glob (pprof_prefix + ".*" ):
336- try :
337- os .remove (f )
338- except Exception as e :
339- print ("Error removing file: {}" .format (e ))
345+ validate_and_cleanup ()
340346
341347
342348class BaseThreadingLockCollectorTest :
0 commit comments