From 8e6f5ba89c7e464aceb8b3faa76cb6fa1379d662 Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 4 Mar 2020 09:22:04 +0100 Subject: [PATCH] NetworkIdentityTests: RebuildObserversDoesNotAddServerConnectionsIfImplemented --- .../Tests/Editor/NetworkIdentityTests.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs index a003e349c..36ca42a56 100644 --- a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs @@ -1417,5 +1417,33 @@ public void RebuildObserversAddsReadyServerConnectionsIfNotImplemented() NetworkServer.Shutdown(); Transport.activeTransport = null; } + + [Test] + public void RebuildObserversDoesNotAddServerConnectionsIfImplemented() + { + // AddObserver will call transport.send and validpacketsize, so we + // actually need a transport + Transport.activeTransport = new MemoryTransport(); + + // add a server connection + NetworkServer.connections[12] = new NetworkConnectionToClient(12){isReady = true}; + + // add at least one observers component, otherwise it will just add + // all server connections + gameObject.AddComponent(); + + // call OnStartServer so that observers dict is created + identity.OnStartServer(); + + // rebuild observers should NOT add all server connections now + identity.RebuildObservers(true); + Assert.That(identity.observers.Count, Is.EqualTo(0)); + + // clean up + NetworkServer.Shutdown(); + Transport.activeTransport = null; + } + + //TODO: // rebuild observers does NOT add a honeypot server conn if any comp implements it? } }