The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [2.0.0-exp.4] - 2024-05-31 ### Added - Added `NetworkRigidbodyBase.AttachToFixedJoint` and `NetworkRigidbodyBase.DetachFromFixedJoint` to replace parenting for rigid bodies that have `NetworkRigidbodyBase.UseRigidBodyForMotion` enabled. (#2933) - Added `NetworkBehaviour.OnNetworkPreSpawn` and `NetworkBehaviour.OnNetworkPostSpawn` methods that provide the ability to handle pre and post spawning actions during the `NetworkObject` spawn sequence. (#2912) - Added a client-side only `NetworkBehaviour.OnNetworkSessionSynchronized` convenience method that is invoked on all `NetworkBehaviour`s after a newly joined client has finished synchronizing with the network session in progress. (#2912) - Added `NetworkBehaviour.OnInSceneObjectsSpawned` convenience method that is invoked when all in-scene `NetworkObject`s have been spawned after a scene has been loaded or upon a host or server starting. (#2912) ### Fixed - Fixed issue where non-authoritative rigid bodies with `NetworkRigidbodyBase.UseRigidBodyForMotion` enabled would constantly log errors about the renderTime being before `StartTimeConsumed`. (#2933) - Fixed issue where in-scene placed NetworkObjects could be destroyed if a client disconnects early and/or before approval. (#2924) - Fixed issue where a `NetworkObject` component's associated `NetworkBehaviour` components would not be detected if scene loading is disabled in the editor and the currently loaded scene has in-scene placed `NetworkObject`s. (#2912) - Fixed issue where an in-scene placed `NetworkObject` with `NetworkTransform` that is also parented under a `GameObject` would not properly synchronize when the parent `GameObject` had a world space position other than 0,0,0. (#2898) ### Changed - Change all the access modifiers of test class from Public to Internal (#2930) - Changed messages are now sorted by enum values as opposed to ordinally sorting the messages by their type name. (#2929) - Changed `NetworkClient.SessionModeTypes` to `NetworkClient.NetworkTopologyTypes`. (#2875) - Changed `NetworkClient.SessionModeType` to `NetworkClient.NetworkTopologyType`. (#2875) - Changed `NetworkConfig.SessionMode` to `NeworkConfig.NetworkTopology`. (#2875)
105 lines
4.5 KiB
C#
105 lines
4.5 KiB
C#
using System.Collections;
|
|
using System.Text.RegularExpressions;
|
|
using NUnit.Framework;
|
|
using Unity.Netcode.TestHelpers.Runtime;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
|
|
namespace Unity.Netcode.RuntimeTests
|
|
{
|
|
[TestFixture(ApprovalTimedOutTypes.ServerDoesNotRespond)]
|
|
[TestFixture(ApprovalTimedOutTypes.ClientDoesNotRequest)]
|
|
internal class ConnectionApprovalTimeoutTests : NetcodeIntegrationTest
|
|
{
|
|
protected override int NumberOfClients => 1;
|
|
|
|
public enum ApprovalTimedOutTypes
|
|
{
|
|
ClientDoesNotRequest,
|
|
ServerDoesNotRespond
|
|
}
|
|
|
|
private ApprovalTimedOutTypes m_ApprovalFailureType;
|
|
|
|
public ConnectionApprovalTimeoutTests(ApprovalTimedOutTypes approvalFailureType)
|
|
{
|
|
m_ApprovalFailureType = approvalFailureType;
|
|
}
|
|
|
|
// Must be >= 5 since this is an int value and the test waits for timeout - 1 to try to verify it doesn't
|
|
// time out early
|
|
private const int k_TestTimeoutPeriod = 5;
|
|
|
|
private Regex m_ExpectedLogMessage;
|
|
private LogType m_LogType;
|
|
|
|
|
|
protected override IEnumerator OnSetup()
|
|
{
|
|
m_BypassConnectionTimeout = true;
|
|
return base.OnSetup();
|
|
}
|
|
|
|
protected override IEnumerator OnTearDown()
|
|
{
|
|
m_BypassConnectionTimeout = false;
|
|
return base.OnTearDown();
|
|
}
|
|
|
|
protected override void OnServerAndClientsCreated()
|
|
{
|
|
m_ServerNetworkManager.NetworkConfig.ClientConnectionBufferTimeout = k_TestTimeoutPeriod;
|
|
m_ServerNetworkManager.LogLevel = LogLevel.Developer;
|
|
m_ClientNetworkManagers[0].NetworkConfig.ClientConnectionBufferTimeout = k_TestTimeoutPeriod;
|
|
m_ClientNetworkManagers[0].LogLevel = LogLevel.Developer;
|
|
base.OnServerAndClientsCreated();
|
|
}
|
|
|
|
protected override IEnumerator OnStartedServerAndClients()
|
|
{
|
|
if (m_ApprovalFailureType == ApprovalTimedOutTypes.ServerDoesNotRespond)
|
|
{
|
|
m_ServerNetworkManager.ConnectionManager.MockSkippingApproval = true;
|
|
// We catch (don't process) the incoming approval message to simulate the server not sending the approved message in time
|
|
m_ClientNetworkManagers[0].ConnectionManager.MessageManager.Hook(new MessageCatcher<ConnectionApprovedMessage>(m_ClientNetworkManagers[0]));
|
|
m_ExpectedLogMessage = new Regex("Timed out waiting for the server to approve the connection request.");
|
|
m_LogType = LogType.Log;
|
|
}
|
|
else
|
|
{
|
|
// We catch (don't process) the incoming connection request message to simulate a transport connection but the client never
|
|
// sends (or takes too long to send) the connection request.
|
|
m_ServerNetworkManager.ConnectionManager.MessageManager.Hook(new MessageCatcher<ConnectionRequestMessage>(m_ServerNetworkManager));
|
|
|
|
// For this test, we know the timed out client will be Client-1
|
|
m_ExpectedLogMessage = new Regex("Server detected a transport connection from Client-1, but timed out waiting for the connection request message.");
|
|
m_LogType = LogType.Warning;
|
|
}
|
|
yield return null;
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator ValidateApprovalTimeout()
|
|
{
|
|
// Just delay for a second
|
|
yield return new WaitForSeconds(1);
|
|
|
|
// Verify we haven't received the time out message yet
|
|
NetcodeLogAssert.LogWasNotReceived(LogType.Log, m_ExpectedLogMessage);
|
|
|
|
yield return new WaitForSeconds(k_TestTimeoutPeriod * 1.25f);
|
|
|
|
// We should have the test relative log message by this time.
|
|
NetcodeLogAssert.LogWasReceived(m_LogType, m_ExpectedLogMessage);
|
|
|
|
VerboseDebug("Checking connected client count");
|
|
// It should only have the host client connected
|
|
Assert.AreEqual(1, m_ServerNetworkManager.ConnectedClients.Count, $"Expected only one client when there were {m_ServerNetworkManager.ConnectedClients.Count} clients connected!");
|
|
|
|
|
|
Assert.AreEqual(0, m_ServerNetworkManager.ConnectionManager.PendingClients.Count, $"Expected no pending clients when there were {m_ServerNetworkManager.ConnectionManager.PendingClients.Count} pending clients!");
|
|
Assert.True(!m_ClientNetworkManagers[0].LocalClient.IsApproved, $"Expected the client to not have been approved, but it was!");
|
|
}
|
|
}
|
|
}
|