From 79c067e4aa72b750eb886de89ab50f0e1ae3f442 Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 16 Jun 2021 12:47:05 +0800 Subject: [PATCH] MirrorTest: ConnectClientBlockingAuthenticatedAndReady helper function --- Assets/Mirror/Tests/Common/MirrorTest.cs | 15 ++++++ .../Mirror/Tests/Editor/NetworkServerTest.cs | 47 ++++--------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/Assets/Mirror/Tests/Common/MirrorTest.cs b/Assets/Mirror/Tests/Common/MirrorTest.cs index e0574d84a..ac4fcbb5f 100644 --- a/Assets/Mirror/Tests/Common/MirrorTest.cs +++ b/Assets/Mirror/Tests/Common/MirrorTest.cs @@ -172,6 +172,21 @@ protected void ConnectClientBlockingAuthenticated(out NetworkConnectionToClient 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() { transport.ClientEarlyUpdate(); diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index d35066f0a..32ba97a85 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -386,11 +386,7 @@ public void ReadyMessageSetsClientReady() { // listen & connect NetworkServer.Listen(1); - ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); - - // send ready message - NetworkClient.Ready(); - ProcessMessages(); + ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient); Assert.That(connectionToClient.isReady, Is.True); } @@ -400,11 +396,7 @@ public void SendCommand() { // listen & connect NetworkServer.Listen(1); - ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); - - // need to be ready for commands - NetworkClient.Ready(); - ProcessMessages(); + ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient); // add an identity with two networkbehaviour components CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp); @@ -431,11 +423,7 @@ public void SendCommand_CalledOnCorrectComponent() { // listen & connect NetworkServer.Listen(1); - ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); - - // need to be ready for commands - NetworkClient.Ready(); - ProcessMessages(); + ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient); // add an identity with two networkbehaviour components CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp0, out CommandTestNetworkBehaviour comp1); @@ -461,11 +449,7 @@ public void SendCommand_OnlyAllowedOnOwnedObjects() { // listen & connect NetworkServer.Listen(1); - ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); - - // need to be ready for commands - NetworkClient.Ready(); - ProcessMessages(); + ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient); // add an identity with two networkbehaviour components CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp); @@ -493,11 +477,7 @@ public void SendCommand_RequiresAuthority() { // listen & connect NetworkServer.Listen(1); - ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); - - // need to be ready for commands - NetworkClient.Ready(); - ProcessMessages(); + ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient); // add an identity with two networkbehaviour components CreateNetworked(out GameObject _, out NetworkIdentity identity, out CommandTestNetworkBehaviour comp); @@ -627,17 +607,12 @@ public void ShowForConnection() { // listen & connect NetworkServer.Listen(1); - ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); + ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient); // overwrite spawn message handler int called = 0; NetworkClient.ReplaceHandler(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 CreateNetworked(out GameObject _, out NetworkIdentity identity); identity.connectionToClient = connectionToClient; @@ -655,6 +630,7 @@ public void ShowForConnection() public void ShowForConnection_OnlyWorksIfReady() { // listen & connect + // DO NOT set ready this time NetworkServer.Listen(1); ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); @@ -662,8 +638,6 @@ public void ShowForConnection_OnlyWorksIfReady() int called = 0; NetworkClient.ReplaceHandler(msg => ++called, false); - // DO NOT set ready this time - // create a gameobject and networkidentity and some unique values CreateNetworked(out GameObject _, out NetworkIdentity identity); identity.connectionToClient = connectionToClient; @@ -682,17 +656,12 @@ public void HideForConnection() { // listen & connect NetworkServer.Listen(1); - ConnectClientBlockingAuthenticated(out NetworkConnectionToClient connectionToClient); + ConnectClientBlockingAuthenticatedAndReady(out NetworkConnectionToClient connectionToClient); // overwrite spawn message handler int called = 0; NetworkClient.ReplaceHandler(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 CreateNetworked(out GameObject _, out NetworkIdentity identity); identity.connectionToClient = connectionToClient;