Skip to content

Commit e0da299

Browse files
chore: Update the port of the codec tests (#3341)
<!-- Replace this block with what this PR does and why. Describe what you'd like reviewers to know, how you applied the engineering principles, and any interesting tradeoffs made. Delete bullet points below that don't apply, and update the changelog section as appropriate. --> - Add a configurable port for the DA codec tests (env variable: `ECHO_SERVER_PORT`) - Add an environment variable (`ENSURE_CODEC_TESTS`) that when set, will fail the codec tests if they fail to connect to an echo-server. The current/default behaviour is to ignore the tests when no echo-server is available - Run the rust echo-server inside yamato so that we can run the codec tests in our yamato tests - Ensure when running the codec tests that the `ENSURE_CODEC_TESTS` variable is set to ensure a test failure if the tests fail to connect to the echo-server <!-- Add short version of the JIRA ticket to the PR title (e.g. "feat: new shiny feature [MTT-123]") --> [MTT-11549](https://jira.unity3d.com/browse/MTT-11549) <!-- Add RFC link here if applicable. --> ## Changelog - Added: Automated testing of the `DistributedAuthorityCodecTests` that run against a rust echo server built off the latest commit on their main branch <!-- Uncomment and mark items off with a * if this PR deprecates any API: ### Deprecated API - [ ] An `[Obsolete]` attribute was added along with a `(RemovedAfter yyyy-mm-dd)` entry. - [ ] An [api updater] was added. - [ ] Deprecation of the API is explained in the CHANGELOG. - [ ] The users can understand why this API was removed and what they should use instead. --> --------- Co-authored-by: Noel Stephens <noel.stephens@unity3d.com>
1 parent fd19d67 commit e0da299

File tree

2 files changed

+66
-12
lines changed

2 files changed

+66
-12
lines changed

.yamato/desktop-standalone-tests.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Builds are made on each supported editor as in project.metafile declaration
88
# Builds are made with different scripting backends as in project.metafile declaration
99
# ARM64 architectures are for now not considered since Windows_arm64 is recommended to use only after builds (would require separation here) and when it comes to macOS_arm64 there is problem with OpenCL not being available
10-
10+
1111
# Build phase
1212
{% for project in projects.default -%}
1313
{% for platform in test_platforms.desktop -%}
@@ -24,20 +24,21 @@ desktop_standalone_build_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
2424
{% if platform.name == "ubuntu" %}
2525
- sudo apt-get update -q
2626
- sudo apt install -qy imagemagick
27+
2728
{% endif %}
2829
- pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
29-
30+
3031
# Platform specific UTR setup
3132
- |
3233
{% if platform.name == "win" %}
3334
curl -s https://artifactory.prd.it.unity3d.com/artifactory/unity-tools-local/utr-standalone/utr.bat --output utr.bat
3435
{% else %}
3536
curl -s https://artifactory.prd.it.unity3d.com/artifactory/unity-tools-local/utr-standalone/utr --output utr && chmod +x utr
3637
{% endif %}
37-
38+
3839
# Installing editor
3940
- unity-downloader-cli -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %} --fast --wait
40-
41+
4142
# Build Player
4243
- |
4344
{% if platform.name == "win" %}
@@ -53,17 +54,17 @@ desktop_standalone_build_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
5354
logs:
5455
paths:
5556
- "artifacts/**/*"
56-
57+
5758
dependencies:
5859
- .yamato/project-pack.yml#project_pack_-_{{ project.name }}_{{ platform.name }}
5960
{% endfor -%}
6061
{% endfor -%}
6162
{% endfor -%}
6263
{% endfor -%}
63-
64-
65-
66-
64+
65+
66+
67+
6768
# Run phase
6869
{% for project in projects.default -%}
6970
{% for platform in test_platforms.desktop -%}
@@ -75,6 +76,16 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
7576
type: {% if platform.name == "mac" %} {{ platform.type }} {% else %} {{ platform.type }}::GPU {% endif %}
7677
image: {{ platform.image }}
7778
flavor: {{ platform.flavor }}
79+
80+
# Set additional variables for running the echo server
81+
{% if platform.name != "win" %}
82+
variables:
83+
ECHO_SERVER_PORT: "7788"
84+
# Set this to ensure the DA codec tests will fail if they cannot connect to the echo-server
85+
# The default is to ignore the codec tests if the echo-server fails to connect
86+
ENSURE_CODEC_TESTS: "true"
87+
{% endif %}
88+
7889
commands:
7990
# Platform specific UTR setup
8091
- |
@@ -86,7 +97,18 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
8697
- pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple
8798

8899
- unity-downloader-cli -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %} --fast --wait
89-
100+
101+
# If ubuntu, run rust echo server
102+
{% if platform.name != "win" %}
103+
- git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
104+
# Install rust
105+
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
106+
# Build the echo server
107+
- cd ./mps-common-multiplayer-backend/runtime && $HOME/.cargo/bin/cargo build --example ngo_echo_server
108+
# Run the echo server in the background - this will reuse the artifacts from the build
109+
- cd ./mps-common-multiplayer-backend/runtime && $HOME/.cargo/bin/cargo run --example ngo_echo_server -- --port $ECHO_SERVER_PORT &
110+
{% endif %}
111+
90112
# Run Standalone tests
91113
- |
92114
{% if platform.name == "win" %}

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)