-
Notifications
You must be signed in to change notification settings - Fork 459
fix: networklog can throw exception when no networkmanager exists #3917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NoelStephensUnity
wants to merge
8
commits into
develop-2.0.0
Choose a base branch
from
fix/networklog-can-throw-exception-when-no-networkmanager-exists
base: develop-2.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eab178e
fix
NoelStephensUnity 5ac4ef6
test
NoelStephensUnity 668c212
update
NoelStephensUnity 2dac37c
style
NoelStephensUnity 3939f31
fix
NoelStephensUnity c3cd512
Merge develop-2.0.0 into fix/networklog-can-throw-exception-when-no-n…
netcode-ci-service 6bf96fa
Merge develop-2.0.0 into fix/networklog-can-throw-exception-when-no-n…
netcode-ci-service 68d7d06
Merge develop-2.0.0 into fix/networklog-can-throw-exception-when-no-n…
netcode-ci-service File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
com.unity.netcode.gameobjects/Tests/Runtime/NetworkLogTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using System.Collections; | ||
| using Unity.Netcode.TestHelpers.Runtime; | ||
| using UnityEngine.TestTools; | ||
|
|
||
| namespace Unity.Netcode.RuntimeTests | ||
| { | ||
| /// <summary> | ||
| /// Validates edge cases with <see cref="NetworkLog"/> | ||
| /// </summary> | ||
| internal class NetworkLogTests : NetcodeIntegrationTest | ||
| { | ||
| protected override int NumberOfClients => 0; | ||
| private bool m_ServerStopped; | ||
|
|
||
| /// <summary> | ||
| /// Validates that if no <see cref="NetworkManager"/> exists, | ||
| /// you can still use NetworkLog with the caveat when one does | ||
| /// not exist it will only log locally. | ||
| /// (is topology agnostic) | ||
| /// </summary> | ||
| [UnityTest] | ||
| public IEnumerator UseNetworkLogWithNoNetworkManager() | ||
| { | ||
| m_ServerStopped = false; | ||
| var authority = GetAuthorityNetworkManager(); | ||
| authority.OnServerStopped += OnServerStopped; | ||
| authority.Shutdown(); | ||
| yield return WaitForConditionOrTimeOut(() => m_ServerStopped); | ||
| AssertOnTimeout($"Timed out waiting for {nameof(NetworkManager)} to stop!"); | ||
| // Assure it is destroyed. | ||
| UnityEngine.Object.Destroy(authority); | ||
| authority = null; | ||
|
|
||
| // Clear out the singleton to assure NetworkLog has no references to a NetworkManager | ||
| NetworkManager.ResetSingleton(); | ||
|
|
||
| // Validate you can use NetworkLog without any NetworkManager instance. | ||
| NetworkLog.LogInfoServer($"Test a message to the server with no {nameof(NetworkManager)}."); | ||
| // No exceptions thrown is considered passing. | ||
| } | ||
|
|
||
| private void OnServerStopped(bool obj) | ||
| { | ||
| m_ServerStopped = true; | ||
| } | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
com.unity.netcode.gameobjects/Tests/Runtime/NetworkLogTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this line making sure that networkManager is not null in any case?
var networkManager = NetworkManagerOverride ??= NetworkManager.Singleton;ResetSingleton shouldn't be used in other context than testing, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. It is to simulate the scenario where a log is generated by something (NetworkObject or NetworkBehaviour) after the fact that the associated NetworkManager has been disposed.