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). ## [1.10.0] - 2024-07-22 ### Added - Added `NetworkBehaviour.OnNetworkPreSpawn` and `NetworkBehaviour.OnNetworkPostSpawn` methods that provide the ability to handle pre and post spawning actions during the `NetworkObject` spawn sequence. (#2906) - 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. (#2906) - 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. (#2906) ### Fixed - Fixed issue where the realtime network stats monitor was not able to display RPC traffic in release builds due to those stats being only available in development builds or the editor. (#2980) - Fixed issue where `NetworkManager.ScenesLoaded` was not being updated if `PostSynchronizationSceneUnloading` was set and any loaded scenes not used during synchronization were unloaded.(#2977) - Fixed issue where internal delta serialization could not have a byte serializer defined when serializing deltas for other types. Added `[GenerateSerializationForType(typeof(byte))]` to both the `NetworkVariable` and `AnticipatedNetworkVariable` classes to assure a byte serializer is defined. (#2953) - Fixed issue with the client count not being correct on the host or server side when a client disconnects itself from a session. (#2941) - Fixed issue with the host trying to send itself a message that it has connected when first starting up. (#2941) - Fixed issue where in-scene placed NetworkObjects could be destroyed if a client disconnects early and/or before approval. (#2923) - Fixed issue where `NetworkDeltaPosition` would "jitter" periodically if both unreliable delta state updates and half-floats were used together. (#2922) - Fixed issue where `NetworkRigidbody2D` would not properly change body type based on the instance's authority when spawned. (#2916) - 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. (#2906) - 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. (#2895) ### Changed
104 lines
4.4 KiB
C#
104 lines
4.4 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)]
|
|
public 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 >= 2 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 = 1;
|
|
|
|
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)
|
|
{
|
|
// 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()
|
|
{
|
|
// Delay for half of the wait period
|
|
yield return new WaitForSeconds(k_TestTimeoutPeriod * 0.25f);
|
|
|
|
// Verify we haven't received the time out message yet
|
|
NetcodeLogAssert.LogWasNotReceived(LogType.Log, m_ExpectedLogMessage);
|
|
|
|
yield return new WaitForSeconds(k_TestTimeoutPeriod * 1.5f);
|
|
|
|
// We should have the test relative log message by this time.
|
|
NetcodeLogAssert.LogWasReceived(m_LogType, m_ExpectedLogMessage);
|
|
|
|
Debug.Log("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!");
|
|
}
|
|
}
|
|
}
|