2222import weakref
2323
2424from synapse .app .homeserver import SynapseHomeServer
25+ from synapse .logging .context import LoggingContext
2526from synapse .storage .background_updates import UpdaterStatus
2627
2728from tests .server import (
2829 cleanup_test_reactor_system_event_triggers ,
2930 get_clock ,
3031 setup_test_homeserver ,
3132)
32- from tests .unittest import HomeserverTestCase
33+ from tests .unittest import HomeserverTestCase , logcontext_clean
3334
3435
3536class HomeserverCleanShutdownTestCase (HomeserverTestCase ):
@@ -44,6 +45,7 @@ def setUp(self) -> None:
4445 # closed in a timely manner during shutdown. Simulating this behaviour in a unit test
4546 # won't be as good as a proper integration test in complement.
4647
48+ @logcontext_clean
4749 def test_clean_homeserver_shutdown (self ) -> None :
4850 """Ensure the `SynapseHomeServer` can be fully shutdown and garbage collected"""
4951 self .reactor , self .clock = get_clock ()
@@ -63,8 +65,13 @@ def test_clean_homeserver_shutdown(self) -> None:
6365 # we use in tests doesn't handle this properly (see doc comment)
6466 cleanup_test_reactor_system_event_triggers (self .reactor )
6567
66- # Cleanup the homeserver.
67- self .get_success (self .hs .shutdown ())
68+ async def shutdown () -> None :
69+ # Use a logcontext just to double-check that we don't mangle the logcontext
70+ # during shutdown.
71+ with LoggingContext (name = "hs_shutdown" , server_name = self .hs .hostname ):
72+ await self .hs .shutdown ()
73+
74+ self .get_success (shutdown ())
6875
6976 # Cleanup the internal reference in our test case
7077 del self .hs
@@ -114,6 +121,7 @@ def test_clean_homeserver_shutdown(self) -> None:
114121 # # to generate the result.
115122 # objgraph.show_backrefs(synapse_hs, max_depth=10, too_many=10)
116123
124+ @logcontext_clean
117125 def test_clean_homeserver_shutdown_mid_background_updates (self ) -> None :
118126 """Ensure the `SynapseHomeServer` can be fully shutdown and garbage collected
119127 before background updates have completed"""
@@ -141,8 +149,13 @@ def test_clean_homeserver_shutdown_mid_background_updates(self) -> None:
141149 # Ensure the background updates are not complete.
142150 self .assertNotEqual (store .db_pool .updates .get_status (), UpdaterStatus .COMPLETE )
143151
144- # Cleanup the homeserver.
145- self .get_success (self .hs .shutdown ())
152+ async def shutdown () -> None :
153+ # Use a logcontext just to double-check that we don't mangle the logcontext
154+ # during shutdown.
155+ with LoggingContext (name = "hs_shutdown" , server_name = self .hs .hostname ):
156+ await self .hs .shutdown ()
157+
158+ self .get_success (shutdown ())
146159
147160 # Cleanup the internal reference in our test case
148161 del self .hs
0 commit comments