Tests: Mirrortest isClient check and make sure it's actually set (#3094)

* Tests: guarantee isClient == true

* fix
This commit is contained in:
vis2k 2022-02-08 20:44:56 +08:00 committed by GitHub
parent 39632fc5e5
commit 2610dfc1b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -182,6 +182,11 @@ protected void CreateNetworkedAndSpawn(
NetworkServer.Spawn(serverGO, ownerConnection);
ProcessMessages();
// double check that client object's isClient is really true!
// previously a test magically failed because isClient was false
// even though it should've been true!
Assert.That(clientIdentity.isClient, Is.True);
// double check that we have authority if we passed an owner connection
if (ownerConnection != null)
Debug.Assert(clientIdentity.hasAuthority == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
@ -237,6 +242,11 @@ protected void CreateNetworkedAndSpawn<T>(
NetworkServer.Spawn(serverGO, ownerConnection);
ProcessMessages();
// double check that client object's isClient is really true!
// previously a test magically failed because isClient was false
// even though it should've been true!
Assert.That(clientIdentity.isClient, Is.True);
// double check that we have authority if we passed an owner connection
if (ownerConnection != null)
Debug.Assert(clientComponent.hasAuthority == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
@ -297,6 +307,11 @@ protected void CreateNetworkedAndSpawn<T, U>(
NetworkServer.Spawn(serverGO, ownerConnection);
ProcessMessages();
// double check that client object's isClient is really true!
// previously a test magically failed because isClient was false
// even though it should've been true!
Assert.That(clientIdentity.isClient, Is.True);
// double check that we have authority if we passed an owner connection
if (ownerConnection != null)
{
@ -363,6 +378,11 @@ protected void CreateNetworkedAndSpawn<T, U, V>(
NetworkServer.Spawn(serverGO, ownerConnection);
ProcessMessages();
// double check that client object's isClient is really true!
// previously a test magically failed because isClient was false
// even though it should've been true!
Assert.That(clientIdentity.isClient, Is.True);
// double check that we have authority if we passed an owner connection
if (ownerConnection != null)
{
@ -428,6 +448,11 @@ protected void CreateNetworkedAndSpawnPlayer(
// make sure the client really spawned it.
Assert.That(clientGO.activeSelf, Is.True);
Assert.That(NetworkClient.spawned.ContainsKey(serverIdentity.netId));
// double check that client object's isClient is really true!
// previously a test magically failed because isClient was false
// even though it should've been true!
Assert.That(clientIdentity.isClient, Is.True);
}
// create GameObject + NetworkIdentity + NetworkBehaviour & SPAWN PLAYER.
@ -485,6 +510,11 @@ protected void CreateNetworkedAndSpawnPlayer<T>(
// make sure the client really spawned it.
Assert.That(clientGO.activeSelf, Is.True);
Assert.That(NetworkClient.spawned.ContainsKey(serverIdentity.netId));
// double check that client object's isClient is really true!
// previously a test magically failed because isClient was false
// even though it should've been true!
Assert.That(clientIdentity.isClient, Is.True);
}
// fully connect client to local server
@ -496,6 +526,13 @@ protected void ConnectClientBlocking(out NetworkConnectionToClient connectionToC
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
connectionToClient = NetworkServer.connections.Values.First();
// set isSpawnFinished flag.
// so that any Spawn() calls will call OnStartClient and set isClient=true
// for the client objects.
// otherwise this would only happen after AddPlayerForConnection.
// but not all tests have a player.
NetworkClient.isSpawnFinished = true;
}
// fully connect client to local server & authenticate
@ -531,6 +568,13 @@ protected void ConnectHostClientBlocking()
NetworkClient.ConnectLocalServer();
UpdateTransport();
Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
// set isSpawnFinished flag.
// so that any Spawn() calls will call OnStartClient and set isClient=true
// for the client objects.
// otherwise this would only happen after AddPlayerForConnection.
// but not all tests have a player.
NetworkClient.isSpawnFinished = true;
}
// fully connect client to local server & authenticate & set read