Skip to content

Commit 35c6d0a

Browse files
committed
Add ENSURE_CODEC_TESTS environment variable
1 parent 4c2ec29 commit 35c6d0a

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

.yamato/desktop-standalone-tests.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
7777
image: {{ platform.image }}
7878
flavor: {{ platform.flavor }}
7979
variables:
80+
{% if platform.name != "win" %}
8081
ECHO_SERVER_PORT: "7788"
82+
# Ensure the DA codec tests will fail if they cannot connect to the echo-server
83+
# The default is to ignore the codec tests if the echo-server fails to connect
84+
ENSURE_CODEC_TESTS: "true"
85+
{% endif %}
8186
commands:
8287
# Platform specific UTR setup
8388
- |
@@ -91,9 +96,8 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
9196
- unity-downloader-cli -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %} --fast --wait
9297

9398
# If ubuntu, run rust echo server
94-
{% if platform.name == "ubuntu" %}
95-
- |
96-
git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
99+
{% if platform.name != "win" %}
100+
- git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
97101
# Install rust
98102
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
99103
# Build the echo server

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace Unity.Netcode.RuntimeTests
2727
/// The tests check if they can bind to a rust echo-server at the given address and port, if all tests are ignored.
2828
/// The rust echo-server is run using `cargo run --example ngo_echo_server -- --port {port}`
2929
/// 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.
3032
/// </remarks>
3133
internal class DistributedAuthorityCodecTests : NetcodeIntegrationTest
3234
{
@@ -60,7 +62,7 @@ private static ushort GetPortToBind()
6062
internal class TestNetworkComponent : NetworkBehaviour
6163
{
6264
public NetworkList<int> MyNetworkList = new NetworkList<int>(new List<int> { 1, 2, 3 });
63-
public NetworkVariable<int> MyNetworkVar = new NetworkVariable<int>(3);
65+
public NetworkVariable<int> myNetworkVar = new NetworkVariable<int>(3);
6466

6567
[Rpc(SendTo.Authority)]
6668
public void TestAuthorityRpc(byte[] _)
@@ -76,7 +78,15 @@ protected override void OnOneTimeSetup()
7678
#else
7779
if (!CanConnectToServer(m_TransportHost, k_TransportPort))
7880
{
79-
Assert.Ignore($"ignoring DA codec tests because UTP transport cannot connect to the rust echo-server at ${m_TransportHost}:{k_TransportPort}");
81+
var shouldFail = Environment.GetEnvironmentVariable("ENSURE_CODEC_TESTS");
82+
if (!string.IsNullOrEmpty(shouldFail))
83+
{
84+
Assert.Fail($"Failed to connect to the rust echo-server at {m_TransportHost}:{k_TransportPort}");
85+
}
86+
else
87+
{
88+
Assert.Ignore($"ignoring DA codec tests because UTP transport cannot connect to the rust echo-server at {m_TransportHost}:{k_TransportPort}");
89+
}
8090
}
8191
#endif
8292
base.OnOneTimeSetup();
@@ -250,9 +260,9 @@ public IEnumerator NetworkVariableDelta_WithValueUpdate()
250260
var component = instance.GetComponent<TestNetworkComponent>();
251261

252262
var newValue = 5;
253-
component.MyNetworkVar.Value = newValue;
263+
component.myNetworkVar.Value = newValue;
254264
yield return m_ClientCodecHook.WaitForMessageReceived<NetworkVariableDeltaMessage>();
255-
Assert.AreEqual(newValue, component.MyNetworkVar.Value);
265+
Assert.AreEqual(newValue, component.myNetworkVar.Value);
256266
}
257267

258268
[UnityTest]

0 commit comments

Comments
 (0)