Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions .yamato/desktop-standalone-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Builds are made on each supported editor as in project.metafile declaration
# Builds are made with different scripting backends as in project.metafile declaration
# 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

# Build phase
{% for project in projects.default -%}
{% for platform in test_platforms.desktop -%}
Expand All @@ -24,20 +24,21 @@ desktop_standalone_build_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
{% if platform.name == "ubuntu" %}
- sudo apt-get update -q
- sudo apt install -qy imagemagick

{% endif %}
- pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple

# Platform specific UTR setup
- |
{% if platform.name == "win" %}
curl -s https://artifactory.prd.it.unity3d.com/artifactory/unity-tools-local/utr-standalone/utr.bat --output utr.bat
{% else %}
curl -s https://artifactory.prd.it.unity3d.com/artifactory/unity-tools-local/utr-standalone/utr --output utr && chmod +x utr
{% endif %}

# Installing editor
- unity-downloader-cli -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %} --fast --wait

# Build Player
- |
{% if platform.name == "win" %}
Expand All @@ -53,17 +54,17 @@ desktop_standalone_build_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
logs:
paths:
- "artifacts/**/*"

dependencies:
- .yamato/project-pack.yml#project_pack_-_{{ project.name }}_{{ platform.name }}
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}




# Run phase
{% for project in projects.default -%}
{% for platform in test_platforms.desktop -%}
Expand All @@ -75,6 +76,16 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
type: {% if platform.name == "mac" %} {{ platform.type }} {% else %} {{ platform.type }}::GPU {% endif %}
image: {{ platform.image }}
flavor: {{ platform.flavor }}

# Set additional variables for running the echo server
{% if platform.name != "win" %}
variables:
ECHO_SERVER_PORT: "7788"
# Set this to ensure the DA codec tests will fail if they cannot connect to the echo-server
# The default is to ignore the codec tests if the echo-server fails to connect
ENSURE_CODEC_TESTS: "true"
{% endif %}

commands:
# Platform specific UTR setup
- |
Expand All @@ -86,7 +97,18 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
- pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple

- unity-downloader-cli -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %} --fast --wait


# If ubuntu, run rust echo server
{% if platform.name != "win" %}
- git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
# Install rust
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# Build the echo server
- cd ./mps-common-multiplayer-backend/runtime && $HOME/.cargo/bin/cargo build --example ngo_echo_server
# Run the echo server in the background - this will reuse the artifacts from the build
- cd ./mps-common-multiplayer-backend/runtime && $HOME/.cargo/bin/cargo run --example ngo_echo_server -- --port $ECHO_SERVER_PORT &
{% endif %}

# Run Standalone tests
- |
{% if platform.name == "win" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@

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

private string m_TransportHost = Environment.GetEnvironmentVariable("NGO_HOST") ?? "127.0.0.1";
private const int k_TransportPort = 7777;
private static readonly ushort k_TransportPort = GetPortToBind();
private const int k_ClientId = 0;

/// <summary>
/// Configures the port to look for the rust echo-server.
/// </summary>
/// <returns>The port from the environment variable "ECHO_SERVER_PORT" if it is set and valid; otherwise uses port 7777</returns>
private static ushort GetPortToBind()
{
var value = Environment.GetEnvironmentVariable("ECHO_SERVER_PORT");
return ushort.TryParse(value, out var configuredPort) ? configuredPort : (ushort)7777;
}

private GameObject m_SpawnObject;

internal class TestNetworkComponent : NetworkBehaviour
Expand All @@ -54,7 +78,15 @@ protected override void OnOneTimeSetup()
#else
if (!CanConnectToServer(m_TransportHost, k_TransportPort))
{
Assert.Ignore("ignoring DA codec tests because UTP transport cannot connect to the runtime");
var shouldFail = Environment.GetEnvironmentVariable("ENSURE_CODEC_TESTS");
if (string.IsNullOrEmpty(shouldFail) || shouldFail.ToLower() == "false")
{
Assert.Ignore($"ignoring DA codec tests because UTP transport cannot connect to the rust echo-server at {m_TransportHost}:{k_TransportPort}");
}
else
{
Assert.Fail($"Failed to connect to the rust echo-server at {m_TransportHost}:{k_TransportPort}");
}
}
#endif
base.OnOneTimeSetup();
Expand Down