Skip to content

Commit e18b84f

Browse files
committed
Merge branch 'test/multiprocess-tests/base-multiprocess-tests' into test/multiprocess-tests/execute-step-in-context
* test/multiprocess-tests/base-multiprocess-tests: fix for automation fail right now fix: (MLAPI.Serialization) 'specified cast is not valid.' on NetworkW… (#951)
2 parents 1e14bd4 + 3d4d863 commit e18b84f

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

com.unity.multiplayer.mlapi/Runtime/Serialization/NetworkWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public void WriteObjectPacked(object value)
210210
{
211211
if (!((NetworkObject)value).IsSpawned)
212212
{
213-
throw new ArgumentException($"{nameof(NetworkWriter)} cannot write {nameof(NetworkObject)} types that are not spawned. {nameof(GameObject)}: {((GameObject)value).name}");
213+
throw new ArgumentException($"{nameof(NetworkWriter)} cannot write {nameof(NetworkObject)} types that are not spawned. {nameof(GameObject)}: {((NetworkObject)value).gameObject.name}");
214214
}
215215

216216
WriteUInt64Packed(((NetworkObject)value).NetworkObjectId);
@@ -220,7 +220,7 @@ public void WriteObjectPacked(object value)
220220
{
221221
if (!((NetworkBehaviour)value).HasNetworkObject || !((NetworkBehaviour)value).NetworkObject.IsSpawned)
222222
{
223-
throw new ArgumentException($"{nameof(NetworkWriter)} cannot write {nameof(NetworkBehaviour)} types that are not spawned. {nameof(GameObject)}: {((GameObject)value).name}");
223+
throw new ArgumentException($"{nameof(NetworkWriter)} cannot write {nameof(NetworkBehaviour)} types that are not spawned. {nameof(GameObject)}: {((NetworkBehaviour)value).gameObject.name}");
224224
}
225225

226226
WriteUInt64Packed(((NetworkBehaviour)value).NetworkObjectId);

com.unity.multiplayer.mlapi/Tests/Editor/NetworkSerializerTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ namespace MLAPI.EditorTests
88
{
99
public class NetworkSerializerTests
1010
{
11+
[Test]
12+
public void SerializeUnspawnedNetworkObject()
13+
{
14+
var gameObject = new GameObject(nameof(SerializeUnspawnedNetworkObject));
15+
var networkObject = gameObject.AddComponent<NetworkObject>();
16+
17+
try
18+
{
19+
using (var outStream = PooledNetworkBuffer.Get())
20+
using (var outWriter = PooledNetworkWriter.Get(outStream))
21+
{
22+
outWriter.WriteObjectPacked(networkObject);
23+
}
24+
25+
// we expect the exception below
26+
Assert.Fail();
27+
}
28+
catch(ArgumentException exception)
29+
{
30+
Assert.True(exception.Message.IndexOf("NetworkWriter cannot write NetworkObject types that are not spawned") != -1);
31+
}
32+
}
33+
1134
[Test]
1235
public void SerializeBool()
1336
{

testproject/Assets/Tests/Runtime/MultiprocessRuntime/BaseMultiprocessTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract class BaseMultiprocessTests
1818
{
1919
protected virtual bool m_IsPerformanceTest => true;
2020

21-
private bool ShouldIgnoreTests => m_IsPerformanceTest && Application.isEditor;
21+
private bool ShouldIgnoreTests => m_IsPerformanceTest && Application.isEditor || MultiprocessOrchestration.IsUsingUTR(); // todo remove UTR check once we have proper automation
2222

2323
/// <summary>
2424
/// Implement this to specify the amount of workers to spawn from your main test runner

testproject/Assets/Tests/Runtime/MultiprocessRuntime/Helpers/MultiprocessOrchestration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.ComponentModel;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using UnityEngine;
67
using Debug = UnityEngine.Debug;
78

@@ -60,4 +61,10 @@ public static void StartWorkerNode()
6061
throw;
6162
}
6263
}
64+
65+
// todo remove this once we have proper automation
66+
public static bool IsUsingUTR()
67+
{
68+
return Environment.GetCommandLineArgs().Contains("-automated");
69+
}
6370
}

0 commit comments

Comments
 (0)