Skip to content

Commit 98a9fe2

Browse files
Merge branch 'develop-2.0.0' into fix/spawn-disabled-in-scene-placed-and-network-prefab-registration
2 parents 4f61564 + 3a09971 commit 98a9fe2

6 files changed

Lines changed: 56 additions & 30 deletions

File tree

.yamato/_triggers.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ pr_code_changes_checks:
8989
# Note that our daily tests will anyway run both test configurations in "minimal supported" and "trunk" configurations
9090
- .yamato/desktop-standalone-tests.yml#desktop_standalone_test_testproject_ubuntu_il2cpp_{{ pinnedTrunk }}
9191
- .yamato/cmb-service-standalone-tests.yml#cmb_service_standalone_test_testproject_ubuntu_il2cpp_{{ pinnedTrunk }}
92-
# Run code coverage test
93-
- .yamato/code-coverage.yml#code_coverage_ubuntu_{{ validation_editors.default }}
92+
# Run code coverage test (PRs use the pinned "safe" trunk)
93+
- .yamato/code-coverage.yml#code_coverage_project_test_testproject_ubuntu_{{ pinnedTrunk }}
9494
triggers:
9595
expression: |-
9696
(pull_request.comment eq "ngo" OR
@@ -159,8 +159,8 @@ develop_nightly:
159159
- .yamato/project-updated-dependencies-test.yml#updated-dependencies_testproject_NGO_win_6000.0
160160
# Run API validation to early-detect all new APIs that would force us to release new minor version of the package. Note that for this to work the package version in package.json must correspond to "actual package state" which means that it should be higher than last released version
161161
- .yamato/vetting-test.yml#vetting_test
162-
# Run code coverage test
163-
- .yamato/code-coverage.yml#code_coverage_ubuntu_{{ validation_editors.default }}
162+
# Run code coverage test (nightly uses actual trunk)
163+
- .yamato/code-coverage.yml#code_coverage_project_test_testproject_ubuntu_trunk
164164

165165

166166
# Run all tests on weekly bases

.yamato/code-coverage.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,37 @@
22
---
33

44
# DESCRIPTION--------------------------------------------------------------------------
5-
# This job is responsible for executing package tests with code coverage analysis enabled.
5+
# This job runs the in-repo testproject tests with code coverage analysis enabled.
6+
# The project tests also exercise the NGO package tests, so a separate package-test coverage job is not needed.
67
# Coverage analysis provides insights into:
78
# Test coverage metrics for NGO assemblies
89
# Line and branch coverage statistics
910
# Generated HTML reports for coverage visualization
1011
# Additional metrics for coverage analysis
1112

1213
# CONFIGURATION STRUCTURE--------------------------------------------------------------
13-
# Jobs are generated using nested loops through:
14-
# 1. For default platform only (Ubuntu) since coverage would not vary between platforms (no need for checks on more platforms)
15-
# 2. For default editor version (trunk) since coverage would not vary between editors (no need for checks on more editors)
14+
# Jobs are generated for:
15+
# 1. Default platform only (Ubuntu) since coverage would not vary between platforms (no need for checks on more platforms)
16+
# 2. Two editors: actual "trunk" (used by nightly) and the "pinnedTrunk" safe version (used by PRs).
17+
# Occasionally trunk breaks our tests, so PRs run against a pinned "safe" trunk while nightly runs actual trunk.
1618

1719
#TECHNICAL CONSIDERATIONS---------------------------------------------------------------
18-
# In theory this job also runs package tests, but we don't want to use it as default since is heavier (because of added coverage analysis) and coverage is not changing that often
1920
# Requires Unity Editor installation
2021
# Burst compilation is disabled to ensure accurate coverage measurement
2122
# In order to properly use -coverage-results-path parameter we need to start it with $PWD (which means the absolute path). Otherwise coverage results will not be visible
2223

2324
# QUALITY CONSIDERATIONS--------------------------------------------------------------------
24-
# To see where this job is included (in trigger job definitions) look into _triggers.yml file
25-
25+
# To see where this job is included (in trigger job definitions) look into _triggers.yml file. Currently:
26+
# [Code Coverage] Project Test runs on PR changes (pr_code_changes_checks, pinnedTrunk) and nightly (develop_nightly, trunk)
2627

28+
{% assign coverage_editors = "trunk," | append: pinnedTrunk | split: "," -%}
2729

2830
{% for platform in test_platforms.default -%}
29-
{% for editor in validation_editors.default -%}
30-
code_coverage_{{ platform.name }}_{{ editor }}:
31-
name: Code Coverage - NGO [{{ platform.name }}, {{ editor }}]
31+
{% for project in projects.default -%}
32+
{% for editor in coverage_editors -%}
33+
{% if editor == "trunk" -%}{% assign editor_label = "trunk" -%}{% else -%}{% assign editor_label = "pinnedTrunk" -%}{% endif -%}
34+
code_coverage_project_test_{{ project.name }}_{{ platform.name }}_{{ editor }}:
35+
name: '[Code Coverage] Project Test - NGO {{ project.name }} [{{ platform.name }}, {{ editor }}]'
3236
agent:
3337
type: {{ platform.type }}
3438
image: {{ platform.image }}
@@ -38,13 +42,14 @@ code_coverage_{{ platform.name }}_{{ editor }}:
3842
{% endif %}
3943
commands:
4044
- unity-downloader-cli --fast --wait -u {{ editor }} -c Editor {% if platform.name == "mac" %} --arch arm64 {% endif %} # For macOS we use ARM64 models
41-
- upm-pvp create-test-project test-project --packages "upm-ci~/packages/*.tgz" --unity .Editor
42-
- UnifiedTestRunner --suite=editor --suite=playmode --editor-location=.Editor --testproject=test-project --enable-code-coverage --coverage-upload-options="reportsDir:$PWD/test-results/CoverageResults;name:NGOv2_{{ platform.name }}_{{ editor }};flags:NGOv2_{{ platform.name }}_{{ editor }};verbose" --coverage-results-path=$PWD/test-results/CoverageResults --coverage-options="generateHtmlReport;generateAdditionalMetrics;assemblyFilters:+Unity.Netcode.Editor,+Unity.Netcode.Runtime" --extra-editor-arg=--burst-disable-compilation --timeout={{ test_timeout }} --rerun-strategy=Test --retry={{ num_test_retries }} --clean-library-on-rerun --artifacts-path=test-results
45+
- UnifiedTestRunner --testproject={{ project.path }} --suite=editor --suite=playmode --editor-location=.Editor --enable-code-coverage --coverage-upload-options="reportsDir:$PWD/test-results/CoverageResults;name:NGOv2_project_{{ project.name }}_{{ platform.name }}_{{ editor_label }};flags:NGOv2_project_{{ project.name }}_{{ platform.name }}_{{ editor_label }};verbose" --coverage-results-path=$PWD/test-results/CoverageResults --coverage-options="generateHtmlReport;generateAdditionalMetrics;assemblyFilters:+Unity.Netcode.Editor,+Unity.Netcode.Runtime" --extra-editor-arg=--burst-disable-compilation --timeout={{ test_timeout }} --rerun-strategy=Test --retry={{ num_test_retries }} --clean-library-on-rerun --artifacts-path=test-results
4346
artifacts:
4447
logs:
4548
paths:
4649
- "test-results/**/*"
4750
dependencies:
51+
- .yamato/_run-all.yml#run_quick_checks # initial checks to perform fast validation of common errors
4852
- .yamato/package-pack.yml#package_pack_-_ngo_{{ platform.name }}
4953
{% endfor -%}
5054
{% endfor -%}
55+
{% endfor -%}

Tools/CI/service.cmb/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Testing against the CMB Service
22

3-
The CMB Service is a tool that is external to our repository. The tool is inside the `runtime` folder in the [mps-common-multiplayer-backend](https://github.com/Unity-Technologies/mps-common-multiplayer-backend) repository.
3+
The CMB Service is a tool that is external to our repository. The tool is inside the `runtime` folder of the [CMB service](https://github.com/Unity-Technologies/unity-player-services/tree/main/services/common-multiplayer-backend) in the Unity Player Services monorepo.
44

55
Due to this, there is some more setup needed when running tests against the CMB Service.
66

@@ -56,3 +56,7 @@ The following environment variables allow for further configuration of the setup
5656
`CMB_SERVICE_PORT` defines the port where the tests will try to connect to the service (defaults to `7789`).
5757

5858
`NGO_HOST` defines the http address where the tests will try to connect to the service (defaults to `127.0.0.1`).
59+
60+
## Running on CI (Yamato)
61+
62+
The CMB tests can also be run from Yamato. The jobs are defined in [`.yamato/cmb-service-standalone-tests.yml`](../../../.yamato/cmb-service-standalone-tests.yml) and appear in Yamato as `CMB Service Test - NGO <project> - [<platform>, <editor>, <backend>]`. The job can be triggered manually from any branch meaning it can be easier to run the CMB tests from Yamato rather than set them up locally. The test uses [`run_cmb_service.sh`](./run_cmb_service.sh) to setup and run the CMB service.

Tools/CI/service.cmb/run_cmb_service.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Example usage:
1818
# ./<path-to-script>/run_cmb_service.sh -e 7788 -s 7799
1919

20-
# This script is currently used in the desktop-standalone-tests yamato job.
20+
# This script is currently used in the cmb-service-standalone-tests yamato job (found at ../../../.yamato/cmb-service-standalone-tests.yml).
2121

2222
# TECHNICAL CONSIDERATIONS---------------------------------------------------------------
2323
# This is a bash script and so needs to be run on a Unix based system.
@@ -136,11 +136,14 @@ else
136136
logMessage "Protocol Buffer Compiler Installed & ENV variables verified!\n PROTOC path is: $PROTOC"
137137
fi
138138

139-
# clone the cmb service repo
140-
git clone https://github.com/Unity-Technologies/mps-common-multiplayer-backend.git
139+
# Sparse-checkout only the CMB service directory from the unity-player-services monorepo.
140+
# --filter=blob:none + --depth 1 avoids downloading file contents and history for the rest of the monorepo.
141+
git clone --depth 1 --filter=blob:none --sparse https://github.com/Unity-Technologies/unity-player-services.git
142+
cd ./unity-player-services
143+
git sparse-checkout set services/common-multiplayer-backend/runtime
141144

142145
# navigate to the cmb service directory
143-
cd ./mps-common-multiplayer-backend/runtime
146+
cd ./services/common-multiplayer-backend/runtime
144147

145148
# Install rust
146149
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

com.unity.netcode.gameobjects/Runtime/Core/FindObjects.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ private struct ObjectsInSceneEnumerator<T> : IEnumerable<T>, IEnumerator<T> wher
6969
internal ObjectsInSceneEnumerator(Scene scene, bool includeInactive)
7070
{
7171
m_IncludeInactive = includeInactive;
72-
73-
m_RootObjects = scene.GetRootGameObjects();
72+
// If the scene is invalid, use an empty array.
73+
m_RootObjects = scene.IsValid() ? scene.GetRootGameObjects() : new UnityEngine.GameObject[0];
7474
m_RootIndex = 0;
7575
m_CurrentChildObjects = null;
7676
m_CurrentChildIndex = 0;

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,17 +3008,31 @@ internal void SynchronizeOwnerNetworkVariables(ulong originalOwnerId, ulong orig
30083008
childBehaviour.MarkOwnerReadDirtyAndCheckOwnerWriteIsDirty();
30093009
}
30103010

3011+
// If the spawn authority of a distributed authority network topology has invoked a change in ownership,
3012+
// then we want to invoke the NetworkBehaviourUpdate prior to changing the owner back.
3013+
if (NetworkManager.DistributedAuthorityMode)
3014+
{
3015+
// Force send a state update for all owner read NetworkVariables and any currently dirty
3016+
// owner write NetworkVariables.
3017+
NetworkManagerOwner.BehaviourUpdater.NetworkBehaviourUpdate(true);
3018+
}
3019+
30113020
// Now set the new owner and previous owner identifiers back to their original new values
3012-
// before we run the NetworkBehaviourUpdate. For owner read only permissions this order of
3013-
// operations is **particularly important** as we need to first (above) mark things as dirty
3014-
// from the context of the original owner and then second (below) we need to send the messages
3015-
// which requires the new owner to be set for owner read permission NetworkVariables.
3021+
// after we run the NetworkBehaviourUpdate.
30163022
OwnerClientId = currentOwnerId;
30173023
PreviousOwnerId = originalOwnerId;
30183024

3019-
// Force send a state update for all owner read NetworkVariables and any currently dirty
3020-
// owner write NetworkVariables.
3021-
NetworkManagerOwner.BehaviourUpdater.NetworkBehaviourUpdate(true);
3025+
// For owner read only permissions this order of operations is **particularly important** as
3026+
// we need to first (above) mark things as dirty from the context of the original owner and
3027+
// then second (below) we need to send the messages which requires the new owner to be set.
3028+
// Note: Owner read only NetworkVariables do not make sense in a distributed authority topology
3029+
// since the only instance that can write is the owner.
3030+
if (!NetworkManager.DistributedAuthorityMode)
3031+
{
3032+
// Force send a state update for all owner read NetworkVariables and any currently dirty
3033+
// owner write NetworkVariables.
3034+
NetworkManagerOwner.BehaviourUpdater.NetworkBehaviourUpdate(true);
3035+
}
30223036
}
30233037

30243038
// NGO currently guarantees that the client will receive spawn data for all objects in one network tick.

0 commit comments

Comments
 (0)