Skip to content

Commit 5ac4ef6

Browse files
test
The test that validates the NetworkLog fix.
1 parent eab178e commit 5ac4ef6

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,14 @@ private void OnTransformParentChanged()
10201020
NetworkManagerCheckForParent();
10211021
}
10221022

1023+
/// <summary>
1024+
/// For testing purposes when you need the singleton to be null
1025+
/// </summary>
1026+
internal static void ResetSingleton()
1027+
{
1028+
Singleton = null;
1029+
}
1030+
10231031
/// <summary>
10241032
/// Set this NetworkManager instance as the static NetworkManager singleton
10251033
/// </summary>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

com.unity.netcode.gameobjects/Tests/Runtime/NetworkLogTests.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)