Skip to content

Commit e95f56c

Browse files
committed
add comments to bash file and explicitly pass env variables to script
1 parent 3783c64 commit e95f56c

File tree

2 files changed

+90
-10
lines changed

2 files changed

+90
-10
lines changed

.yamato/desktop-standalone-tests.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,25 @@ desktop_standalone_test_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
8080
# Set additional variables for running the echo server (This is needed ONLY for NGOv2.X because relates to Distributed Authority)
8181
{% if platform.name != "win" %} # Issues with win and mac are tracked in MTT-11606
8282
variables:
83+
# The echo server is a "mock" server that is only used to test encoding/decoding of messages.
84+
# It is used by the DistributedAuthorityCodecTests. These are tests that are built and maintained by the CMB service team.
8385
ECHO_SERVER_PORT: "7788"
84-
CMB_SERVICE_PORT: "7799"
85-
# Set this to ensure the DA codec tests will fail if they cannot connect to the echo-server
86-
# The default is to ignore the codec tests if the echo-server fails to connect
86+
# Set this to ensure the DistributedAuthorityCodecTests will fail if they cannot connect to the echo server.
87+
# The default is to ignore the codec tests if the echo server fails to connect
8788
ENSURE_CODEC_TESTS: "true"
89+
90+
# When USE_CMB_SERVICE is set to true, any C# tests configured to use the DA host will instead use the CMB service.
8891
USE_CMB_SERVICE: "true"
92+
# This is the port on which to run the full standalone CMB service.
93+
# The port needs to be different from the echo server port as two processes cannot bind to same port.
94+
CMB_SERVICE_PORT: "7799"
8995
{% endif %}
9096

9197
commands:
9298
# If ubuntu, run rust echo server (This is needed ONLY for NGOv2.X because relates to Distributed Authority)
9399
{% if platform.name != "win" %} # Issues with win and mac are tracked in MTT-11606
94-
- ./Tools/CI/run_cmb_service.sh
100+
# run_cmb_service.sh builds and starts a release version of the full CMB service (along with the limited echo server)
101+
- ./Tools/CI/run_cmb_service.sh -e $ECHO_SERVER_PORT -s $CMB_SERVICE_PORT
95102
{% endif %}
96103

97104
- unity-downloader-cli --fast --wait -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %} {% if platform.name == "mac" %} --arch arm64 {% endif %} # For macOS we use ARM64 models

Tools/CI/run_cmb_service.sh

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,92 @@
1-
# clone the latest rust repo
1+
#!/bin/bash
2+
3+
# DESCRIPTION--------------------------------------------------------------------------
4+
# This bash file is used to build and run CMB service resources.
5+
# These are resources relating to the distributed authority feature. The CMB service is built and maintained by the services team.
6+
7+
# CONTENTS-----------------------------------------------------------------------------
8+
# There are two resources that are built and run:
9+
# 1. The echo server - this is a "mock" server that simply echoes back the messages it receives. It is used to test message serialization.
10+
# The echo server is used inside the DistributedAuthorityCodecTests. These are tests that are built and maintained by the CMB service team.
11+
# 2. The standalone server - this is a release build of the full CMB service.
12+
13+
# USAGE---------------------------------------------------------------------------------
14+
# The script requires ports to be defined. This works via the following command:
15+
# ./<path-to-script>/run_cmb_service.sh -e <echo-server-port> -s <cmb-service-port>
16+
17+
# Example usage:
18+
# ./<path-to-script>/run_cmb_service.sh -e 7788 -s 7799
19+
20+
# This script is currently used in the desktop-standalone-tests yamato job.
21+
22+
# TECHNICAL CONSIDERATIONS---------------------------------------------------------------
23+
# This is a bash script and so needs to be run on a Unix based system.
24+
# - It runs on mac and ubuntu bokken machines. It will not run on windows bokken machines.
25+
26+
# This script starts processes running in the background. All logs are still written to stdout and will be seen in the logs of the job.
27+
# Running in the background means that the processes will continue to run after the script exits.
28+
# This is not a concern for bokken machines as all processes are killed when the machine is shut down.
29+
30+
# QUALITY THOUGHTS--------------------------------------------------------------------
31+
# Currently this script simply uses the head of the cmb service repo.
32+
# We might want to consider using the latest released version in the future.
33+
34+
#-------------------------------------------------------------------------------------
35+
36+
# Define error message if ports are not defined
37+
ERROR="Error: Expected ports to be defined! Example script usage:"
38+
EXAMPLE="run_cmb_service.sh -e <echo-server-port> -s <cmb-service-port>"
39+
40+
# get arguments passed to the script
41+
while getopts 'e:s:' flag; do
42+
case "${flag}" in
43+
e) echo_port="${OPTARG}" ;;
44+
s) service_port="${OPTARG}" ;;
45+
*) printf "%s\n" "$ERROR" "$EXAMPLE"
46+
exit 1 ;;
47+
esac
48+
done
49+
50+
# ensure arguments were passed and the ports are defined
51+
if [ -z "$echo_port" ] || [ -z "$service_port" ]; then
52+
printf "%s\n" "$ERROR" "$EXAMPLE";
53+
exit 1;
54+
elif [[ "$echo_port" == "$service_port" ]]; then
55+
printf "Ports cannot be the same! Please use different ports.\n";
56+
exit 1;
57+
fi
58+
59+
echo "Starting with echo server on port: $echo_port and the cmb service on port: $service_port"
60+
61+
# Setup -------------------------------------------------------------------------
62+
63+
# clone the cmb service repo
264
git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
65+
# navigate to the cmb service directory
366
cd ./mps-common-multiplayer-backend/runtime
467

568
# Install rust
669
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
70+
# Add the cargo bin directory to the PATH
771
export PATH="$HOME/.cargo/bin:$PATH"
872

73+
74+
# Echo server -------------------------------------------------------------------
75+
976
# Build the echo server
1077
cargo build --example ngo_echo_server
78+
# Run the echo server in the background
79+
cargo run --example ngo_echo_server -- --port $echo_port &
80+
1181

12-
# Run the echo server in the background - this will reuse the artifacts from the build
13-
cargo run --example ngo_echo_server -- --port $ECHO_SERVER_PORT &
82+
# CMB Service -------------------------------------------------------------------
1483

15-
# Build a release version of the standalone server
84+
# Build a release version of the standalone cmb service
1685
cargo build --release --locked
1786

18-
# Run the standalone server on an infinite loop in the background
19-
while :; do ./target/release/comb-server -l error --metrics-port 5000 standalone --port $CMB_SERVICE_PORT -t 60m; done &
87+
# Run the standalone service on an infinite loop in the background.
88+
# The infinite loop is required as the service will exit each time all connected clients disconnect.
89+
# This means the service will exit after each test. The infinite loop will immediately restart the service each time it exits.
90+
while :; do
91+
./target/release/comb-server -l error --metrics-port 5000 standalone --port $service_port -t 60m;
92+
done & # <- use & to run the entire loop in the background

0 commit comments

Comments
 (0)