|
| 1 | +using System.Collections; |
| 2 | +using Unity.Netcode.TestHelpers.Runtime; |
| 3 | +using UnityEngine.TestTools; |
| 4 | + |
| 5 | +namespace Unity.Netcode.RuntimeTests |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// Validates edge cases with <see cref="NetworkLog"/> |
| 9 | + /// </summary> |
| 10 | + internal class NetworkLogTests : NetcodeIntegrationTest |
| 11 | + { |
| 12 | + protected override int NumberOfClients => 0; |
| 13 | + private bool m_ServerStopped; |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// Validates that if no <see cref="NetworkManager"/> exists, |
| 17 | + /// you can still use NetworkLog with the caveat when one does |
| 18 | + /// not exist it will only log locally. |
| 19 | + /// (is topology agnostic) |
| 20 | + /// </summary> |
| 21 | + [UnityTest] |
| 22 | + public IEnumerator UseNetworkLogWithNoNetworkManager() |
| 23 | + { |
| 24 | + m_ServerStopped = false; |
| 25 | + var authority = GetAuthorityNetworkManager(); |
| 26 | + authority.OnServerStopped += OnServerStopped; |
| 27 | + authority.Shutdown(); |
| 28 | + yield return WaitForConditionOrTimeOut(() => m_ServerStopped); |
| 29 | + AssertOnTimeout($"Timed out waiting for {nameof(NetworkManager)} to stop!"); |
| 30 | + // Assure it is destroyed. |
| 31 | + UnityEngine.Object.Destroy(authority); |
| 32 | + authority = null; |
| 33 | + |
| 34 | + // Clear out the singleton to assure NetworkLog has no references to a NetworkManager |
| 35 | + NetworkManager.ResetSingleton(); |
| 36 | + |
| 37 | + // Validate you can use NetworkLog without any NetworkManager instance. |
| 38 | + NetworkLog.LogInfoServer($"Test a message to the server with no {nameof(NetworkManager)}."); |
| 39 | + // No exceptions thrown is considered passing. |
| 40 | + } |
| 41 | + |
| 42 | + private void OnServerStopped(bool obj) |
| 43 | + { |
| 44 | + m_ServerStopped = true; |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments