MirrorTest: ConnectClientBlockingAuthenticatedAndReady helper function

This commit is contained in:
vis2k 2021-06-16 12:47:05 +08:00
parent 2df5357647
commit 79c067e4aa
2 changed files with 23 additions and 39 deletions

View File

@ -172,6 +172,21 @@ protected void ConnectClientBlockingAuthenticated(out NetworkConnectionToClient
NetworkClient.connection.isAuthenticated = true; NetworkClient.connection.isAuthenticated = true;
} }
// fully connect client to local server & authenticate & set read
protected void ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient)
{
ConnectClientBlocking(out connectionToClient);
// authenticate server & client connections
connectionToClient.isAuthenticated = true;
NetworkClient.connection.isAuthenticated = true;
// set ready
NetworkClient.Ready();
ProcessMessages();
Assert.That(connectionToClient.isReady, Is.True);
}
protected void UpdateTransport() protected void UpdateTransport()
{ {
transport.ClientEarlyUpdate(); transport.ClientEarlyUpdate();

View File

@ -386,11 +386,7 @@ public void ReadyMessageSetsClientReady()
{ {
// listen & connect // listen & connect
NetworkServer.Listen(1); NetworkServer.Listen(1);
ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient);
// send ready message
NetworkClient.Ready();
ProcessMessages();
Assert.That(connectionToClient.isReady, Is.True); Assert.That(connectionToClient.isReady, Is.True);
} }
@ -400,11 +396,7 @@ public void SendCommand()
{ {
// listen & connect // listen & connect
NetworkServer.Listen(1); NetworkServer.Listen(1);
ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient);
// need to be ready for commands
NetworkClient.Ready();
ProcessMessages();
// add an identity with two networkbehaviour components // add an identity with two networkbehaviour components
CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp); CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp);
@ -431,11 +423,7 @@ public void SendCommand_CalledOnCorrectComponent()
{ {
// listen & connect // listen & connect
NetworkServer.Listen(1); NetworkServer.Listen(1);
ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient);
// need to be ready for commands
NetworkClient.Ready();
ProcessMessages();
// add an identity with two networkbehaviour components // add an identity with two networkbehaviour components
CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp0, out CommandTestNetworkBehaviour comp1); CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp0, out CommandTestNetworkBehaviour comp1);
@ -461,11 +449,7 @@ public void SendCommand_OnlyAllowedOnOwnedObjects()
{ {
// listen & connect // listen & connect
NetworkServer.Listen(1); NetworkServer.Listen(1);
ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient);
// need to be ready for commands
NetworkClient.Ready();
ProcessMessages();
// add an identity with two networkbehaviour components // add an identity with two networkbehaviour components
CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp); CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp);
@ -493,11 +477,7 @@ public void SendCommand_RequiresAuthority()
{ {
// listen & connect // listen & connect
NetworkServer.Listen(1); NetworkServer.Listen(1);
ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient);
// need to be ready for commands
NetworkClient.Ready();
ProcessMessages();
// add an identity with two networkbehaviour components // add an identity with two networkbehaviour components
CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp); CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp);
@ -627,17 +607,12 @@ public void ShowForConnection()
{ {
// listen & connect // listen & connect
NetworkServer.Listen(1); NetworkServer.Listen(1);
ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient);
// overwrite spawn message handler // overwrite spawn message handler
int called = 0; int called = 0;
NetworkClient.ReplaceHandler<SpawnMessage>(msg => ++called, false); NetworkClient.ReplaceHandler<SpawnMessage>(msg => ++called, false);
// ready is required for ShowForConnection
NetworkClient.Ready();
ProcessMessages();
Assert.That(connectionToClient.isReady, Is.True);
// create a gameobject and networkidentity and some unique values // create a gameobject and networkidentity and some unique values
CreateNetworked(out GameObject _, out NetworkIdentity identity); CreateNetworked(out GameObject _, out NetworkIdentity identity);
identity.connectionToClient = connectionToClient; identity.connectionToClient = connectionToClient;
@ -655,6 +630,7 @@ public void ShowForConnection()
public void ShowForConnection_OnlyWorksIfReady() public void ShowForConnection_OnlyWorksIfReady()
{ {
// listen & connect // listen & connect
// DO NOT set ready this time
NetworkServer.Listen(1); NetworkServer.Listen(1);
ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient);
@ -662,8 +638,6 @@ public void ShowForConnection_OnlyWorksIfReady()
int called = 0; int called = 0;
NetworkClient.ReplaceHandler<SpawnMessage>(msg => ++called, false); NetworkClient.ReplaceHandler<SpawnMessage>(msg => ++called, false);
// DO NOT set ready this time
// create a gameobject and networkidentity and some unique values // create a gameobject and networkidentity and some unique values
CreateNetworked(out GameObject _, out NetworkIdentity identity); CreateNetworked(out GameObject _, out NetworkIdentity identity);
identity.connectionToClient = connectionToClient; identity.connectionToClient = connectionToClient;
@ -682,17 +656,12 @@ public void HideForConnection()
{ {
// listen & connect // listen & connect
NetworkServer.Listen(1); NetworkServer.Listen(1);
ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient);
// overwrite spawn message handler // overwrite spawn message handler
int called = 0; int called = 0;
NetworkClient.ReplaceHandler<ObjectHideMessage>(msg => ++called, false); NetworkClient.ReplaceHandler<ObjectHideMessage>(msg => ++called, false);
// ready is required for ShowForConnection
NetworkClient.Ready();
ProcessMessages();
Assert.That(connectionToClient.isReady, Is.True);
// create a gameobject and networkidentity and some unique values // create a gameobject and networkidentity and some unique values
CreateNetworked(out GameObject _, out NetworkIdentity identity); CreateNetworked(out GameObject _, out NetworkIdentity identity);
identity.connectionToClient = connectionToClient; identity.connectionToClient = connectionToClient;