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