Skip to content

Commit 240eba5

Browse files
committed
Next round of fixes
1 parent a779769 commit 240eba5

5 files changed

Lines changed: 92 additions & 13 deletions

File tree

‎.yamato/console-standalone-test.yml‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,17 @@ console_standalone_test_{{ project.name }}_{{ platform.name }}_{{ editor }}:
8888
model: {{ platform.model }} # This is set only in platforms where we want non-default model to use (more information in project.metafile)
8989
{% endif %}
9090
commands:
91-
- UnifiedTestRunner --suite=playmode --platform={{ platform.standalone }} --scripting-backend=il2cpp --testproject={{ project.path }} --artifacts-path=test-results --player-load-path=build/players --fail-on-assert --rerun-strategy=Test --retry={{ num_test_retries }} --timeout={{ test_timeout }}
91+
# Console players connect back to UTR's player connection listener on this VM, so the firewall must allow it
92+
- command: gsudo NetSh Advfirewall set allprofiles state off
93+
# Register the Bokken devkit with the platform's target tools so UTR can deploy and run the prebuilt player
94+
{% if platform.name == "ps5" %}
95+
- command: gsudo prospero-ctrl target add %BOKKEN_DEVICE_IP%
96+
{% elsif platform.name == "ps4" %}
97+
- command: orbis-ctrl add %BOKKEN_DEVICE_IP%
98+
{% else %}
99+
- command: '"%GameDK%/bin/xbconnect" /WS %BOKKEN_DEVICE_IP%'
100+
{% endif %}
101+
- UnifiedTestRunner --suite=playmode --platform={{ platform.standalone }} --scripting-backend=il2cpp --testproject={{ project.path }} --artifacts-path=test-results --player-load-path=build/players --player-connection-ip=%BOKKEN_HOST_IP% --fail-on-assert --rerun-strategy=Test --retry={{ num_test_retries }} --timeout={{ test_timeout }}
92102
variables:
93103
# PS4 related
94104
SCE_ORBIS_SDK_DIR: 'C:\Users\bokken\SCE\ps4_sdk_12_00'

‎.yamato/desktop-standalone-tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ desktop_standalone_build_{{ project.name }}_{{ platform.name }}_{{ backend }}_{{
4949
{% endif %}
5050
commands:
5151
- unity-downloader-cli --fast --wait -u {{ editor }} -c Editor {% if backend == "il2cpp" %} -c il2cpp {% endif %}{% if backend == "coreclr" %}{% unless coreclr_runtime_editors contains editor %} -c {{ platform.coreclr_component }} {% endunless %}{% endif %} --arch {{ platform.architecture }}
52-
- UnifiedTestRunner --suite=playmode --platform={{ platform.standalone }} --editor-location=.Editor --testproject={{ project.path }} --scripting-backend={{ backend }} --testfilter="Unity.Netcode.RuntimeTests.*;TestProject.RuntimeTests.*" --player-save-path=build/players --artifacts-path=artifacts --extra-editor-arg=-batchmode --extra-editor-arg=-nographics --reruncount=1 --clean-library-on-rerun --build-only --timeout={{ test_timeout }}
52+
- UnifiedTestRunner --suite=playmode --platform={{ platform.standalone }} --editor-location=.Editor --testproject={{ project.path }} --scripting-backend={{ backend }} --testfilter="Unity.Netcode.RuntimeTests.*;TestProject.RuntimeTests.*" --playergraphicsapi=Null --player-save-path=build/players --artifacts-path=artifacts --extra-editor-arg=-batchmode --extra-editor-arg=-nographics --reruncount=1 --clean-library-on-rerun --build-only --timeout={{ test_timeout }}
5353
artifacts:
5454
players:
5555
paths:

‎com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/IntegrationTestSceneHandler.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ private bool ExcludeSceneFromSynchronizationCheck(Scene scene)
372372

373373
public void ClearSceneTracking(NetworkManager networkManager)
374374
{
375-
SceneNameToSceneHandles.Clear();
375+
// Only clear the calling NetworkManager's tracking, other NetworkManagers may still be tracking their own scenes
376+
SceneNameToSceneHandles.Remove(networkManager);
376377
}
377378

378379
public void StopTrackingScene(NetworkSceneHandle handle, string name, NetworkManager networkManager)

‎com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTest.cs‎

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ public IEnumerator SetUp()
831831
// In addition to setting the number of clients in the OneTimeSetup, we need to re-apply the number of clients for each unique test
832832
// in the event that a previous test stopped a client.
833833
m_NumberOfClients = NumberOfClients;
834+
// Clear any time out state left by a previous test so it cannot fail this test's assertions
835+
s_GlobalTimeoutHelper.TimedOut = false;
834836
VerboseDebugLog.Clear();
835837
VerboseDebug($"Entering {nameof(SetUp)}");
836838
NetcodeLogAssert = new NetcodeLogAssert();
@@ -1261,7 +1263,7 @@ protected void CreateAndStartNewClientWithTimeTravel()
12611263

12621264
// Wait for the new client to connect
12631265
var connected = WaitForClientsConnectedOrTimeOutWithTimeTravel();
1264-
AssertOnTimeout($"{nameof(CreateAndStartNewClientWithTimeTravel)} timed out waiting for all clients to be connected!\n {m_InternalErrorLog}");
1266+
Assert.IsTrue(connected, $"{nameof(CreateAndStartNewClientWithTimeTravel)} timed out waiting for all clients to be connected!\n {m_InternalErrorLog}");
12651267

12661268
OnNewClientStartedAndConnected(networkManager);
12671269
if (!connected)
@@ -1644,9 +1646,9 @@ protected void StartServerAndClientsWithTimeTravel()
16441646
if (!m_BypassConnectionTimeout)
16451647
{
16461648
// Wait for all clients to connect
1647-
WaitForClientsConnectedOrTimeOutWithTimeTravel();
1649+
var connected = WaitForClientsConnectedOrTimeOutWithTimeTravel();
16481650

1649-
AssertOnTimeout($"{nameof(StartServerAndClients)} timed out waiting for all clients to be connected!\n {m_InternalErrorLog}");
1651+
Assert.IsTrue(connected, $"{nameof(StartServerAndClients)} timed out waiting for all clients to be connected!\n {m_InternalErrorLog}");
16501652

16511653
if (m_UseHost || authorityManager.IsHost)
16521654
{
@@ -1669,8 +1671,8 @@ protected void StartServerAndClientsWithTimeTravel()
16691671
{
16701672
foreach (var networkManager in m_NetworkManagers)
16711673
{
1672-
WaitForConditionOrTimeOutWithTimeTravel(() => AllPlayerObjectClonesSpawned(networkManager));
1673-
AssertOnTimeout($"{nameof(CreateAndStartNewClient)} timed out waiting for all sessions to spawn Client-{networkManager.LocalClientId}'s player object!");
1674+
var spawned = WaitForConditionOrTimeOutWithTimeTravel(() => AllPlayerObjectClonesSpawned(networkManager));
1675+
Assert.IsTrue(spawned, $"{nameof(CreateAndStartNewClient)} timed out waiting for all sessions to spawn Client-{networkManager.LocalClientId}'s player object!");
16741676
}
16751677
}
16761678

@@ -1771,7 +1773,7 @@ protected void ShutdownAndCleanUp()
17711773
}
17721774
catch (Exception e)
17731775
{
1774-
throw e;
1776+
Debug.LogException(e);
17751777
}
17761778
finally
17771779
{
@@ -1909,6 +1911,9 @@ public IEnumerator TearDown()
19091911
{
19101912
ShutdownAndCleanUp();
19111913
}
1914+
1915+
// Wait until all the scene from this test are unloaded before starting the next test.
1916+
yield return WaitForRemainingScenesUnloaded();
19121917
}
19131918

19141919
if (m_EnableTimeTravel)
@@ -2975,22 +2980,72 @@ protected void AssertOnTimeout(string timeOutErrorMessage, TimeoutHelper assigne
29752980
}
29762981

29772982

2983+
private const float k_SceneUnloadTimeout = 5.0f;
2984+
private readonly List<AsyncOperation> m_PendingSceneUnloads = new List<AsyncOperation>();
2985+
29782986
private void UnloadRemainingScenes()
29792987
{
29802988
// Unload any remaining scenes loaded but the test runner scene
29812989
// Note: Some tests only unload the server-side instance, and this
29822990
// just assures no currently loaded scenes will impact the next test
2991+
Scene testRunnerScene = default;
29832992
for (int i = 0; i < SceneManager.sceneCount; i++)
29842993
{
29852994
var scene = SceneManager.GetSceneAt(i);
2986-
if (!scene.IsValid() || !scene.isLoaded || scene.name.Contains(NetcodeIntegrationTestHelpers.FirstPartOfTestRunnerSceneName) || !OnCanSceneCleanUpUnload(scene))
2995+
if (scene.name.Contains(NetcodeIntegrationTestHelpers.FirstPartOfTestRunnerSceneName)) {
2996+
testRunnerScene = scene;
2997+
continue;
2998+
}
2999+
if (!scene.IsValid() || !scene.isLoaded || !OnCanSceneCleanUpUnload(scene))
29873000
{
29883001
continue;
29893002
}
29903003

29913004
VerboseDebug($"Unloading scene {scene.name}-{scene.handle}");
29923005
var asyncOperation = SceneManager.UnloadSceneAsync(scene);
3006+
if (asyncOperation != null)
3007+
{
3008+
m_PendingSceneUnloads.Add(asyncOperation);
3009+
}
3010+
}
3011+
3012+
// Ensure the test runner scene is reset to be the active scene.
3013+
if (testRunnerScene.IsValid())
3014+
{
3015+
if (SceneManager.GetActiveScene() != testRunnerScene)
3016+
{
3017+
SceneManager.SetActiveScene(testRunnerScene);
3018+
}
3019+
3020+
}
3021+
}
3022+
3023+
/// <summary>
3024+
/// Waits (in real time) for all scenes left over by the test to finish unloading.
3025+
/// Scenes that finish loading after tear down started are also unloaded.
3026+
/// </summary>
3027+
private IEnumerator WaitForRemainingScenesUnloaded()
3028+
{
3029+
var timeOut = Time.realtimeSinceStartup + k_SceneUnloadTimeout;
3030+
while (true)
3031+
{
3032+
// Pick up any scenes that finished loading after the clean up started
3033+
UnloadRemainingScenes();
3034+
3035+
if (m_PendingSceneUnloads.All(c => c.isDone))
3036+
{
3037+
break;
3038+
}
3039+
3040+
if (Time.realtimeSinceStartup >= timeOut)
3041+
{
3042+
Debug.LogWarning($"[{nameof(WaitForRemainingScenesUnloaded)}] Timed out waiting for scenes to unload!");
3043+
break;
3044+
}
3045+
yield return null;
29933046
}
3047+
3048+
m_PendingSceneUnloads.Clear();
29943049
}
29953050

29963051
private StringBuilder m_WaitForLog = new StringBuilder();

‎com.unity.netcode.gameobjects/Tests/Runtime/TestHelpers/NetcodeIntegrationTestHelpers.cs‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,16 +478,29 @@ public static void Destroy()
478478

479479
try
480480
{
481-
// Shutdown the server which forces clients to disconnect
481+
NetworkManager sessionAuthority = null;
482+
// Shutdown clients first
482483
foreach (var networkManager in NetworkManagerInstances)
483484
{
484-
if (networkManager != null && networkManager.IsListening)
485+
if (networkManager.LocalClient.IsSessionOwner || networkManager.IsServer)
485486
{
486-
networkManager?.Shutdown();
487+
sessionAuthority = networkManager;
488+
}
489+
else
490+
{
491+
networkManager.Shutdown();
487492
s_Hooks.Remove(networkManager);
488493
}
489494
}
490495

496+
// Shutdown the server/session owner last
497+
// This avoids session owner election when running CMB tests
498+
if (sessionAuthority != null)
499+
{
500+
sessionAuthority.Shutdown();
501+
s_Hooks.Remove(sessionAuthority);
502+
}
503+
491504
// Destroy the network manager instances
492505
foreach (var networkManager in NetworkManagerInstances)
493506
{

0 commit comments

Comments
 (0)