mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fixing TearDown and removing extra calls to shutdown (#1722)
This commit is contained in:
parent
3368026b2c
commit
db87c961b0
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -69,10 +69,11 @@ public void SetUp()
|
|||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDown()
|
public void TearDown()
|
||||||
{
|
{
|
||||||
Transport.activeTransport = null;
|
|
||||||
|
|
||||||
// reset all state
|
// reset all state
|
||||||
|
// shutdown should be called before setting activeTransport to null
|
||||||
NetworkServer.Shutdown();
|
NetworkServer.Shutdown();
|
||||||
|
|
||||||
|
Transport.activeTransport = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -104,9 +105,6 @@ public void MaxConnectionsTest()
|
|||||||
// connect second: should fail
|
// connect second: should fail
|
||||||
Transport.activeTransport.OnServerConnected.Invoke(43);
|
Transport.activeTransport.OnServerConnected.Invoke(43);
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -125,9 +123,6 @@ public void ConnectMessageHandlerTest()
|
|||||||
// connect
|
// connect
|
||||||
Transport.activeTransport.OnServerConnected.Invoke(42);
|
Transport.activeTransport.OnServerConnected.Invoke(42);
|
||||||
Assert.That(connectCalled, Is.True);
|
Assert.That(connectCalled, Is.True);
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -150,9 +145,6 @@ public void DisconnectMessageHandlerTest()
|
|||||||
// disconnect
|
// disconnect
|
||||||
Transport.activeTransport.OnServerDisconnected.Invoke(42);
|
Transport.activeTransport.OnServerDisconnected.Invoke(42);
|
||||||
Assert.That(disconnectCalled, Is.True);
|
Assert.That(disconnectCalled, Is.True);
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -185,9 +177,6 @@ public void ConnectionsDictTest()
|
|||||||
// disconnect first
|
// disconnect first
|
||||||
Transport.activeTransport.OnServerDisconnected.Invoke(42);
|
Transport.activeTransport.OnServerDisconnected.Invoke(42);
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -216,9 +205,6 @@ public void OnConnectedOnlyAllowsGreaterZeroConnectionIdsTest()
|
|||||||
Transport.activeTransport.OnServerConnected.Invoke(-1);
|
Transport.activeTransport.OnServerConnected.Invoke(-1);
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||||
LogAssert.ignoreFailingMessages = false;
|
LogAssert.ignoreFailingMessages = false;
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -242,9 +228,6 @@ public void ConnectDuplicateConnectionIdsTest()
|
|||||||
Transport.activeTransport.OnServerConnected.Invoke(42);
|
Transport.activeTransport.OnServerConnected.Invoke(42);
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
|
||||||
Assert.That(NetworkServer.connections[42], Is.EqualTo(original));
|
Assert.That(NetworkServer.connections[42], Is.EqualTo(original));
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -265,9 +248,6 @@ public void SetLocalConnectionTest()
|
|||||||
NetworkServer.SetLocalConnection(overwrite);
|
NetworkServer.SetLocalConnection(overwrite);
|
||||||
Assert.That(NetworkServer.localConnection, Is.EqualTo(localConnection));
|
Assert.That(NetworkServer.localConnection, Is.EqualTo(localConnection));
|
||||||
LogAssert.ignoreFailingMessages = false;
|
LogAssert.ignoreFailingMessages = false;
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -288,9 +268,6 @@ public void RemoveLocalConnectionTest()
|
|||||||
// remove local connection
|
// remove local connection
|
||||||
NetworkServer.RemoveLocalConnection();
|
NetworkServer.RemoveLocalConnection();
|
||||||
Assert.That(NetworkServer.localConnection, Is.Null);
|
Assert.That(NetworkServer.localConnection, Is.Null);
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -303,9 +280,6 @@ public void LocalClientActiveTest()
|
|||||||
// set local connection
|
// set local connection
|
||||||
NetworkServer.SetLocalConnection(new ULocalConnectionToClient());
|
NetworkServer.SetLocalConnection(new ULocalConnectionToClient());
|
||||||
Assert.That(NetworkServer.localClientActive, Is.True);
|
Assert.That(NetworkServer.localClientActive, Is.True);
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -347,9 +321,6 @@ public void AddConnectionTest()
|
|||||||
Assert.That(NetworkServer.connections[42], Is.EqualTo(conn42));
|
Assert.That(NetworkServer.connections[42], Is.EqualTo(conn42));
|
||||||
Assert.That(NetworkServer.connections.ContainsKey(43), Is.True);
|
Assert.That(NetworkServer.connections.ContainsKey(43), Is.True);
|
||||||
Assert.That(NetworkServer.connections[43], Is.EqualTo(conn43));
|
Assert.That(NetworkServer.connections[43], Is.EqualTo(conn43));
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -376,9 +347,6 @@ public void RemoveConnectionTest()
|
|||||||
bool resultRemove = NetworkServer.RemoveConnection(42);
|
bool resultRemove = NetworkServer.RemoveConnection(42);
|
||||||
Assert.That(resultRemove, Is.True);
|
Assert.That(resultRemove, Is.True);
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -401,9 +369,6 @@ public void DisconnectAllConnectionsTest()
|
|||||||
// disconnect all connections
|
// disconnect all connections
|
||||||
NetworkServer.DisconnectAllConnections();
|
NetworkServer.DisconnectAllConnections();
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -432,9 +397,6 @@ public void DisconnectAllTest()
|
|||||||
NetworkServer.DisconnectAll();
|
NetworkServer.DisconnectAll();
|
||||||
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));
|
||||||
Assert.That(NetworkServer.localConnection, Is.Null);
|
Assert.That(NetworkServer.localConnection, Is.Null);
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -481,9 +443,6 @@ public void OnDataReceivedTest()
|
|||||||
Assert.That(wasReceived, Is.True);
|
Assert.That(wasReceived, Is.True);
|
||||||
Assert.That(connectionReceived, Is.EqualTo(connection));
|
Assert.That(connectionReceived, Is.EqualTo(connection));
|
||||||
Assert.That(messageReceived, Is.EqualTo(testMessage));
|
Assert.That(messageReceived, Is.EqualTo(testMessage));
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -524,9 +483,6 @@ public void OnDataReceivedInvalidConnectionIdTest()
|
|||||||
// message handler should never be called
|
// message handler should never be called
|
||||||
Assert.That(wasReceived, Is.False);
|
Assert.That(wasReceived, Is.False);
|
||||||
Assert.That(connectionReceived, Is.Null);
|
Assert.That(connectionReceived, Is.Null);
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -592,9 +548,6 @@ public void ReadyMessageSetsClientReadyTest()
|
|||||||
|
|
||||||
// ready?
|
// ready?
|
||||||
Assert.That(connection.isReady, Is.True);
|
Assert.That(connection.isReady, Is.True);
|
||||||
|
|
||||||
// shutdown
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this runs a command all the way:
|
// this runs a command all the way:
|
||||||
@ -768,9 +721,6 @@ public void SendToAllTest()
|
|||||||
|
|
||||||
// was it send to and handled by the connection?
|
// was it send to and handled by the connection?
|
||||||
Assert.That(called, Is.EqualTo(1));
|
Assert.That(called, Is.EqualTo(1));
|
||||||
|
|
||||||
// clean up
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -834,9 +784,6 @@ public void RegisterUnregisterClearHandlerTest()
|
|||||||
LogAssert.ignoreFailingMessages = false;
|
LogAssert.ignoreFailingMessages = false;
|
||||||
// still 1, not 2
|
// still 1, not 2
|
||||||
Assert.That(variant2Called, Is.EqualTo(1));
|
Assert.That(variant2Called, Is.EqualTo(1));
|
||||||
|
|
||||||
// clean up
|
|
||||||
NetworkServer.Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
Loading…
Reference in New Issue
Block a user