NetworkServerTests: ConnectDuplicateConnectionIdsTest

This commit is contained in:
vis2k 2020-02-24 10:51:04 +01:00
parent 9c325abbd8
commit ad0d20144a

View File

@ -167,6 +167,32 @@ public void OnConnectedOnlyAllowsGreaterZeroConnectionIdsTest()
NetworkServer.Shutdown(); NetworkServer.Shutdown();
} }
[Test]
public void ConnectDuplicateConnectionIdsTest()
{
// message handlers
NetworkServer.RegisterHandler<ConnectMessage>((conn, msg) => {}, false);
NetworkServer.RegisterHandler<DisconnectMessage>((conn, msg) => {}, false);
NetworkServer.RegisterHandler<ErrorMessage>((conn, msg) => {}, false);
// listen
NetworkServer.Listen(2);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
// connect first
Transport.activeTransport.OnServerConnected.Invoke(42);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
NetworkConnectionToClient original = NetworkServer.connections[42];
// connect duplicate - shouldn't overwrite first one
Transport.activeTransport.OnServerConnected.Invoke(42);
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
Assert.That(NetworkServer.connections[42], Is.EqualTo(original));
// shutdown
NetworkServer.Shutdown();
}
[Test] [Test]
public void SetLocalConnectionTest() public void SetLocalConnectionTest()
{ {