@@ -236,6 +236,46 @@ public IEnumerator OnClientAndServerStartedCalledWhenHostStarts()
236236 Assert . AreEqual ( 2 , callbacksInvoked , "either OnServerStarted or OnClientStarted wasn't invoked" ) ;
237237 }
238238
239+ [ UnityTest ]
240+ public IEnumerator OnPreShutdownCalledWhenShuttingDown ( )
241+ {
242+ bool preShutdownInvoked = false ;
243+ bool shutdownInvoked = false ;
244+ var gameObject = new GameObject ( nameof ( OnPreShutdownCalledWhenShuttingDown ) ) ;
245+ m_ServerManager = gameObject . AddComponent < NetworkManager > ( ) ;
246+
247+ // Set dummy transport that does nothing
248+ var transport = gameObject . AddComponent < DummyTransport > ( ) ;
249+ m_ServerManager . NetworkConfig = new NetworkConfig ( ) { NetworkTransport = transport } ;
250+
251+ Action onPreShutdown = ( ) =>
252+ {
253+ preShutdownInvoked = true ;
254+ Assert . IsFalse ( shutdownInvoked , "OnPreShutdown was invoked after OnServerStopped" ) ;
255+ } ;
256+
257+ Action < bool > onServerStopped = ( bool wasAlsoClient ) =>
258+ {
259+ shutdownInvoked = true ;
260+ Assert . IsTrue ( preShutdownInvoked , "OnPreShutdown wasn't invoked before OnServerStopped" ) ;
261+ } ;
262+
263+ // Start server to cause initialization process
264+ Assert . True ( m_ServerManager . StartServer ( ) ) ;
265+ Assert . True ( m_ServerManager . IsListening ) ;
266+
267+ m_ServerManager . OnPreShutdown += onPreShutdown ;
268+ m_ServerManager . OnServerStopped += onServerStopped ;
269+ m_ServerManager . Shutdown ( ) ;
270+ Object . DestroyImmediate ( gameObject ) ;
271+
272+ yield return WaitUntilManagerShutsdown ( ) ;
273+
274+ Assert . False ( m_ServerManager . IsListening ) ;
275+ Assert . True ( preShutdownInvoked , "OnPreShutdown wasn't invoked" ) ;
276+ Assert . True ( shutdownInvoked , "OnServerStopped wasn't invoked" ) ;
277+ }
278+
239279 private IEnumerator WaitUntilManagerShutsdown ( )
240280 {
241281 /* Need two updates to actually shut down. First one to see the transport failing, which
0 commit comments