From 47b1aa74001073ecf50a5eb6eab4d008345f9411 Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 27 Feb 2020 10:10:07 +0100 Subject: [PATCH] NetworkIdentityTests: OnStopAuthorityComponentExceptionIsCaught --- .../Tests/Editor/NetworkIdentityTests.cs | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs index ea8edfba6..c5bb4c5da 100644 --- a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs @@ -52,6 +52,16 @@ public override void OnStartAuthority() } } + class StopAuthorityExceptionNetworkBehaviour : NetworkBehaviour + { + public int called; + public override void OnStopAuthority() + { + ++called; + throw new Exception("some exception"); + } + } + // A Test behaves as an ordinary method [Test] public void OnStartServerTest() @@ -386,16 +396,39 @@ public void OnStartAuthorityComponentExceptionIsCaught() // create a networkidentity with our test component GameObject gameObject = new GameObject(); NetworkIdentity identity = gameObject.AddComponent(); - StartClientExceptionNetworkBehaviour comp = gameObject.AddComponent(); + StartAuthorityExceptionNetworkBehaviour comp = gameObject.AddComponent(); - // make sure that comp.OnStartClient was called and make sure that + // make sure that comp.OnStartAuthority was called and make sure that // the exception was caught and not thrown in here. - // an exception in OnStartClient should be caught, so that one + // an exception in OnStartAuthority should be caught, so that one // component's exception doesn't stop all other components from // being initialized // (an error log is expected though) LogAssert.ignoreFailingMessages = true; - identity.OnStartClient(); // should catch the exception internally and not throw it + identity.OnStartAuthority(); // should catch the exception internally and not throw it + Assert.That(comp.called, Is.EqualTo(1)); + LogAssert.ignoreFailingMessages = false; + + // clean up + GameObject.DestroyImmediate(gameObject); + } + + [Test] + public void OnStopAuthorityComponentExceptionIsCaught() + { + // create a networkidentity with our test component + GameObject gameObject = new GameObject(); + NetworkIdentity identity = gameObject.AddComponent(); + StopAuthorityExceptionNetworkBehaviour comp = gameObject.AddComponent(); + + // make sure that comp.OnStopAuthority was called and make sure that + // the exception was caught and not thrown in here. + // an exception in OnStopAuthority should be caught, so that one + // component's exception doesn't stop all other components from + // being initialized + // (an error log is expected though) + LogAssert.ignoreFailingMessages = true; + identity.OnStopAuthority(); // should catch the exception internally and not throw it Assert.That(comp.called, Is.EqualTo(1)); LogAssert.ignoreFailingMessages = false;