File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -39,3 +39,60 @@ async def test_daemon_exit_causes_parent_cancellation():
39
39
assert not service .is_running
40
40
41
41
await asyncio .wait_for (service .events .cleaned_up .wait (), timeout = 1 )
42
+
43
+
44
+ @pytest .mark .asyncio
45
+ async def test_service_tasks_do_not_leak_memory ():
46
+ service = WaitService ()
47
+ asyncio .ensure_future (service .run ())
48
+
49
+ end = asyncio .Event ()
50
+
51
+ async def run_until_end ():
52
+ await end .wait ()
53
+
54
+ service .run_task (run_until_end ())
55
+
56
+ # inspect internals to determine if memory is leaking
57
+
58
+ # confirm that task is tracked:
59
+ assert len (service ._tasks ) == 1
60
+
61
+ end .set ()
62
+ # allow the coro to exit
63
+ await asyncio .sleep (0 )
64
+
65
+ # confirm that task is no longer tracked:
66
+ assert len (service ._tasks ) == 0
67
+
68
+ # test cleanup
69
+ await service .cancel ()
70
+
71
+
72
+ @pytest .mark .asyncio
73
+ async def test_service_children_do_not_leak_memory ():
74
+ parent = WaitService ()
75
+ child = WaitService ()
76
+ asyncio .ensure_future (parent .run ())
77
+
78
+ parent .run_child_service (child )
79
+
80
+ # inspect internals to determine if memory is leaking
81
+
82
+ # confirm that child service is tracked:
83
+ assert len (parent ._child_services ) == 1
84
+
85
+ # give child a chance to start
86
+ await asyncio .sleep (0 )
87
+
88
+ # ... and then end it
89
+ await child .cancel ()
90
+
91
+ # remove the final reference to the child service
92
+ del child
93
+
94
+ # confirm that child service is no longer tracked:
95
+ assert len (parent ._child_services ) == 0
96
+
97
+ # test cleanup
98
+ await parent .cancel ()
You can’t perform that action at this time.
0 commit comments