@@ -41,17 +41,35 @@ def test_shutdown_gracefully(client_session):
4141 assert not server .clients
4242
4343
44- class TestServerThreaded ():
44+ class TestServerThreadedWithoutClient ():
4545 def test_run_forever (self , threaded_server ):
4646 assert threaded_server .thread
4747 assert not isinstance (threaded_server .thread , threading ._MainThread )
4848 assert threaded_server .thread .is_alive ()
4949
5050 def test_shutdown (self , threaded_server ):
5151 assert threaded_server .thread .is_alive ()
52+
53+ # Shutdown de-facto way
54+ # REF: https://docs.python.org/3/library/socketserver.html
55+ # "Tell the serve_forever() loop to stop and
56+ # wait until it does. shutdown() must be called while serve_forever()
57+ # is running in a different thread otherwise it will deadlock."
5258 threaded_server .shutdown ()
5359 assert not threaded_server .thread .is_alive ()
5460
61+ def test_shutdown_gracefully_without_clients (self , threaded_server ):
62+ assert threaded_server .thread .is_alive ()
63+ threaded_server .shutdown_gracefully ()
64+ assert not threaded_server .thread .is_alive ()
65+ assert threaded_server .socket .fileno () <= 0
66+
67+ def test_shutdown_abruptly_without_clients (self , threaded_server ):
68+ assert threaded_server .thread .is_alive ()
69+ threaded_server .shutdown_abruptly ()
70+ assert not threaded_server .thread .is_alive ()
71+ assert threaded_server .socket .fileno () <= 0
72+
5573
5674def test_shutdown_abruptly (client_session ):
5775 client , server = client_session
0 commit comments