Skip to content

Commit e3e3339

Browse files
committed
Fix tests
1 parent e3955b7 commit e3e3339

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -907,10 +907,7 @@ internal NetworkObject GetNetworkObjectToSpawn(uint globalObjectIdHash, ulong ow
907907
// If not, then there is an issue (user possibly didn't register the prefab properly?)
908908
if (networkPrefabReference == null)
909909
{
910-
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
911-
{
912-
NetworkLog.LogErrorServer($"[{nameof(globalObjectIdHash)}={globalObjectIdHash}] Failed to create object locally. {nameof(NetworkPrefab)} could not be found. Is the prefab registered with {NetworkManager.name}?");
913-
}
910+
NetworkManager.Log.ErrorServer(new Context(LogLevel.Error, $"Failed to create object locally. {nameof(NetworkPrefab)} could not be found. Is the prefab registered with this {nameof(NetworkManager)}").AddInfo(nameof(NetworkObject.GlobalObjectIdHash), globalObjectIdHash).AddTag(NetworkManager.name));
914911
return null;
915912
}
916913

@@ -1196,7 +1193,7 @@ internal bool NonAuthorityLocalSpawn(in NetworkObject.SerializedObject serialize
11961193
// Log the error that the NetworkObject failed to construct
11971194
if (networkObject == null)
11981195
{
1199-
NetworkManager.Log.ErrorServer(new Context(LogLevel.Normal, $"Failed to spawn {nameof(NetworkObject)}").AddInfo(nameof(NetworkObject.GlobalObjectIdHash), serializedObject.Hash));
1196+
NetworkManager.Log.ErrorServer(new Context(LogLevel.Normal, $"Failed to spawn {nameof(NetworkObject)}!").AddInfo(nameof(NetworkObject.GlobalObjectIdHash), serializedObject.Hash));
12001197
return false;
12011198
}
12021199

com.unity.netcode.gameobjects/Tests/Runtime/Prefabs/NetworkPrefabHandlerSynchronizationTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using System.Text.RegularExpressions;
23
using NUnit.Framework;
34
using Unity.Netcode.TestHelpers.Runtime;
45
using UnityEngine;
@@ -42,7 +43,11 @@ public IEnumerator NetworkPrefabHandlerSpawnAndSynchronizeTests()
4243

4344
// Check the invalid object spawns on the authority, expect an error from non-authority.
4445
LogAssert.Expect(LogType.Exception, "Exception: exception while instantiating");
45-
LogAssert.Expect(LogType.Error, $"[Netcode] [GlobalObjectIdHash={exceptionObject.GlobalObjectIdHash}] Failed to spawn NetworkObject!");
46+
LogAssert.Expect(LogType.Error, new Regex("Failed to spawn NetworkObject!"));
47+
// Authority should receive an error from non-authority and should use the globalObjectIdHash to find the failing object
48+
LogAssert.Expect(LogType.Error, new Regex($@"SenderId:{nonAuthority.LocalClientId}\]\[{Regex.Escape(exceptionObject.name)}"));
49+
// LogAssert.Expect(LogType.Error, new Regex(Regex.Escape(exceptionObject.name)));
50+
// LogAssert.Expect(LogType.Error, "[Netcode] [Received log from client][SenderId:1][ClientSideExceptionPrefab{3}-OnServer{0}][NetworkObjectId:3] [NonAuthorityLocalSpawn][GlobalObjectIdHash:111115] Failed to spawn NetworkObject!");
4651
yield return WaitForConditionOrTimeOut(() => exceptionObject.IsSpawned);
4752
AssertOnTimeout("Failed to spawn object on authority!");
4853

@@ -58,9 +63,13 @@ public IEnumerator NetworkPrefabHandlerSpawnAndSynchronizeTests()
5863
newClient.PrefabHandler.AddHandler(m_ClientSideExceptionPrefab, new NetworkPrefabExceptionThrower());
5964
newClient.PrefabHandler.AddHandler(m_ValidPrefab, new NetworkPrefabInstanceHandler(networkObjectToSpawnOnClient));
6065

61-
// Expect assertions fromt the new client
66+
// Expect assertions from the new client
6267
LogAssert.Expect(LogType.Exception, "Exception: exception while instantiating");
63-
LogAssert.Expect(LogType.Error, $"[Netcode] [GlobalObjectIdHash={exceptionObject.GlobalObjectIdHash}] Failed to spawn NetworkObject!");
68+
LogAssert.Expect(LogType.Error, new Regex("Failed to spawn NetworkObject!"));
69+
70+
// Authority will receive an error from new client and should use the globalObjectIdHash to find the failing object
71+
var expectedNewClientId = nonAuthority.LocalClientId + 1;
72+
LogAssert.Expect(LogType.Error, new Regex($@"SenderId:{expectedNewClientId}\]\[{Regex.Escape(exceptionObject.name)}"));
6473

6574
// Start and synchronize the new client
6675
yield return StartClient(newClient);

testproject/Assets/Tests/Runtime/PrefabExtendedTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Text;
54
using NUnit.Framework;
65
using TestProject.ManualTests;
@@ -213,9 +212,6 @@ public enum InstantiateAndSpawnMethods
213212
[UnityTest]
214213
public IEnumerator TestPrefabsSpawning([Values] InstantiateAndSpawnMethods instantiateAndSpawnType)
215214
{
216-
var gloabalObjectId = m_SceneManagementEnabled ? 0 : InScenePlacedHelper.ServerInSceneDefined.First().GlobalObjectIdHash;
217-
var firstError = $"[Netcode] Failed to create object locally. [globalObjectIdHash={gloabalObjectId}]. NetworkPrefab could not be found. Is the prefab registered with NetworkManager?";
218-
var secondError = $"[Netcode] Failed to spawn NetworkObject for Hash {gloabalObjectId}.";
219215
m_InstantiateAndSpawnType = instantiateAndSpawnType;
220216

221217
// We have to spawn the first client manually in order to account for the errors when scene management is disabled.
@@ -224,7 +220,6 @@ public IEnumerator TestPrefabsSpawning([Values] InstantiateAndSpawnMethods insta
224220
// spawn the original prefab and when spawning dynamically the override is used.
225221
yield return CreateAndStartNewClient();
226222

227-
var spawnManager = m_ServerNetworkManager.SpawnManager;
228223
// If scene management is enabled, then we want to verify against the editor
229224
// assigned in-scene placed NetworkObjects
230225
if (m_SceneManagementEnabled)

0 commit comments

Comments
 (0)