diff --git a/.yamato/desktop-standalone-tests.yml b/.yamato/desktop-standalone-tests.yml index b12c71f2eb..bdacea3d49 100644 --- a/.yamato/desktop-standalone-tests.yml +++ b/.yamato/desktop-standalone-tests.yml @@ -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 -%} @@ -24,9 +24,10 @@ 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" %} @@ -34,10 +35,10 @@ desktop_standalone_build_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{ {% 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" %} @@ -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 -%} @@ -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 - | @@ -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" %} diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/DistributedAuthority/DistributedAuthorityCodecTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/DistributedAuthority/DistributedAuthorityCodecTests.cs index 398d0403ee..2947b5830f 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/DistributedAuthority/DistributedAuthorityCodecTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/DistributedAuthority/DistributedAuthorityCodecTests.cs @@ -16,6 +16,20 @@ namespace Unity.Netcode.RuntimeTests { + /// + /// This class tests the NGO message codec between the C# SDK and the Rust runtime. + /// + /// + /// 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. + /// internal class DistributedAuthorityCodecTests : NetcodeIntegrationTest { protected override int NumberOfClients => 1; @@ -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; + /// + /// Configures the port to look for the rust echo-server. + /// + /// The port from the environment variable "ECHO_SERVER_PORT" if it is set and valid; otherwise uses port 7777 + 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 @@ -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();