Skip to content

Commit df41be9

Browse files
Merge branch 'develop-2.0.0' into ci-corrections-develop-2.0.0
2 parents 7ce8fde + 429b256 commit df41be9

File tree

4 files changed

+68
-7
lines changed

4 files changed

+68
-7
lines changed

.yamato/desktop-standalone-tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,31 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
7070
type: {% if platform.name == "mac" %} {{ platform.type }} {% else %} {{ platform.type }}::GPU {% endif %}
7171
image: {{ platform.image }}
7272
flavor: {{ platform.flavor }}
73+
74+
# Set additional variables for running the echo server
75+
{% if platform.name != "win" %}
76+
variables:
77+
ECHO_SERVER_PORT: "7788"
78+
# Set this to ensure the DA codec tests will fail if they cannot connect to the echo-server
79+
# The default is to ignore the codec tests if the echo-server fails to connect
80+
ENSURE_CODEC_TESTS: "true"
81+
{% endif %}
82+
7383
commands:
7484
- unity-downloader-cli -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %}
7585
- UnifiedTestRunner --suite=playmode --player-load-path=build/players --artifacts-path=test-results --testproject={{ project.path }} --editor-location=.Editor --playergraphicsapi=Null --fail-on-assert --reruncount=1 --clean-library-on-rerun --timeout=1800
86+
87+
# If ubuntu, run rust echo server
88+
{% if platform.name != "win" %}
89+
- git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
90+
# Install rust
91+
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
92+
# Build the echo server
93+
- cd ./mps-common-multiplayer-backend/runtime && $HOME/.cargo/bin/cargo build --example ngo_echo_server
94+
# Run the echo server in the background - this will reuse the artifacts from the build
95+
- cd ./mps-common-multiplayer-backend/runtime && $HOME/.cargo/bin/cargo run --example ngo_echo_server -- --port $ECHO_SERVER_PORT &
96+
{% endif %}
97+
7698
artifacts:
7799
logs:
78100
paths:

com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,16 +1173,17 @@ internal void OnClientDisconnectFromServer(ulong clientId)
11731173
if (ownedObject)
11741174
{
11751175
// If destroying with owner, then always despawn and destroy (or defer destroying to prefab handler)
1176-
if (!ownedObject.DontDestroyWithOwner)
1176+
// Handle an object with no observers other than the current disconnecting client as destroying with owner
1177+
if (!ownedObject.DontDestroyWithOwner || ownedObject.Observers.Count == 0 || (ownedObject.Observers.Count == 1 && ownedObject.Observers.Contains(clientId)))
11771178
{
1178-
if (NetworkManager.PrefabHandler.ContainsHandler(clientOwnedObjects[i].GlobalObjectIdHash))
1179+
if (NetworkManager.PrefabHandler.ContainsHandler(ownedObject.GlobalObjectIdHash))
11791180
{
11801181
if (ownedObject.IsSpawned)
11811182
{
11821183
// Don't destroy (prefab handler will determine this, but always notify
11831184
NetworkManager.SpawnManager.DespawnObject(ownedObject, false, true);
11841185
}
1185-
NetworkManager.PrefabHandler.HandleNetworkPrefabDestroy(clientOwnedObjects[i]);
1186+
NetworkManager.PrefabHandler.HandleNetworkPrefabDestroy(ownedObject);
11861187
}
11871188
else
11881189
{
@@ -1240,6 +1241,12 @@ internal void OnClientDisconnectFromServer(ulong clientId)
12401241
{
12411242
continue;
12421243
}
1244+
1245+
// Skip destroy with owner objects as they will be processed by the outer loop
1246+
if (!childObject.DontDestroyWithOwner || childObject.Observers.Count == 0 || (childObject.Observers.Count == 1 && childObject.Observers.Contains(clientId)))
1247+
{
1248+
continue;
1249+
}
12431250
// If the client owner disconnected, it is ok to unlock this at this point in time.
12441251
if (childObject.IsOwnershipLocked)
12451252
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,8 +1975,8 @@ internal void DistributeNetworkObjects(ulong clientId)
19751975
// the owned distributable parent with the owned distributable children
19761976
foreach (var child in children)
19771977
{
1978-
// Ignore the parent and any child that does not have the same owner or that is already owned by the currently targeted client
1979-
if (child == ownerList.Value[i] || child.OwnerClientId != ownerList.Value[i].OwnerClientId || child.OwnerClientId == clientId)
1978+
// Ignore any child that does not have the same owner, that is already owned by the currently targeted client, or that doesn't have the targeted client as an observer
1979+
if (child == ownerList.Value[i] || child.OwnerClientId != ownerList.Value[i].OwnerClientId || child.OwnerClientId == clientId || !child.Observers.Contains(clientId))
19801980
{
19811981
continue;
19821982
}

com.unity.netcode.gameobjects/Tests/Runtime/DistributedAuthority/DistributedAuthorityCodecTests.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616

1717
namespace Unity.Netcode.RuntimeTests
1818
{
19+
/// <summary>
20+
/// This class tests the NGO message codec between the C# SDK and the Rust runtime.
21+
/// </summary>
22+
/// <remarks>
23+
/// These tests are run against a rust echo-server.
24+
/// This server decodes incoming messages, and then re-encodes them before sending them back to the client.
25+
/// Any errors in decoding or encoding messages will not echo the messages back, causing the tests to fail
26+
/// No message handling logic is tested in these tests. They are only testing the codec.
27+
/// The tests check if they can bind to a rust echo-server at the given address and port, if all tests are ignored.
28+
/// The rust echo-server is run using `cargo run --example ngo_echo_server -- --port {port}`
29+
/// The C# port can be configured using the environment variable "ECHO_SERVER_PORT"
30+
/// The default behaviour when unity fails to connect to the echo-server is to ignore all tests in this class.
31+
/// This can be overridden by setting the environment variable "ENSURE_CODEC_TESTS" to any value - then the tests will fail.
32+
/// </remarks>
1933
internal class DistributedAuthorityCodecTests : NetcodeIntegrationTest
2034
{
2135
protected override int NumberOfClients => 1;
@@ -30,9 +44,19 @@ internal class DistributedAuthorityCodecTests : NetcodeIntegrationTest
3044
private NetworkManager Client => m_ClientNetworkManagers[0];
3145

3246
private string m_TransportHost = Environment.GetEnvironmentVariable("NGO_HOST") ?? "127.0.0.1";
33-
private const int k_TransportPort = 7777;
47+
private static readonly ushort k_TransportPort = GetPortToBind();
3448
private const int k_ClientId = 0;
3549

50+
/// <summary>
51+
/// Configures the port to look for the rust echo-server.
52+
/// </summary>
53+
/// <returns>The port from the environment variable "ECHO_SERVER_PORT" if it is set and valid; otherwise uses port 7777</returns>
54+
private static ushort GetPortToBind()
55+
{
56+
var value = Environment.GetEnvironmentVariable("ECHO_SERVER_PORT");
57+
return ushort.TryParse(value, out var configuredPort) ? configuredPort : (ushort)7777;
58+
}
59+
3660
private GameObject m_SpawnObject;
3761

3862
internal class TestNetworkComponent : NetworkBehaviour
@@ -54,7 +78,15 @@ protected override void OnOneTimeSetup()
5478
#else
5579
if (!CanConnectToServer(m_TransportHost, k_TransportPort))
5680
{
57-
Assert.Ignore("ignoring DA codec tests because UTP transport cannot connect to the runtime");
81+
var shouldFail = Environment.GetEnvironmentVariable("ENSURE_CODEC_TESTS");
82+
if (string.IsNullOrEmpty(shouldFail) || shouldFail.ToLower() == "false")
83+
{
84+
Assert.Ignore($"ignoring DA codec tests because UTP transport cannot connect to the rust echo-server at {m_TransportHost}:{k_TransportPort}");
85+
}
86+
else
87+
{
88+
Assert.Fail($"Failed to connect to the rust echo-server at {m_TransportHost}:{k_TransportPort}");
89+
}
5890
}
5991
#endif
6092
base.OnOneTimeSetup();

0 commit comments

Comments
 (0)