-
Notifications
You must be signed in to change notification settings - Fork 456
fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback. [MTT-1378] #1739
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
fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback. [MTT-1378] #1739
Conversation
…ocessing of the next callback.
Also review feedback.
testproject/Assets/Tests/Runtime/OnNetworkSpawnExceptionTests.cs
Outdated
Show resolved
Hide resolved
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.
Want to understand more about the absorbing of exceptions
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.
+1 for Debug.LogException()
instead of NetworkLog.LogError()
both in spawn and despawn flows.
also LogAssert.Expect
exists, that'd potentially make tests simpler too.
Surley we want to use NetworkLog though? Perhaps adding NetworkLog.LogException Otherwise NetworkLog is incomplete if only half the logs are networked. |
I see your point @TwoTenPvP but I think |
Personally I prefer a bit worse log messages than an incomplete feature. NetworkLog.LogError / Debug.LogException. I think using NetworkLog.LogError is the best choice if NetworkLog.LogException is out of the question |
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.
Looks perfectly fine to me!
(except the integration test)
🙈
Closed and re-opened to fix the JIRA association. Please make sure to add the JIRA ticket to the title upon PR creation in the future. |
# Conflicts: # com.unity.netcode.gameobjects/CHANGELOG.md # com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
private GameObject[] m_Objects = new GameObject[5]; | ||
|
||
[UnityTest] | ||
public IEnumerator WhenOnNetworkSpawnThrowsException_FutureOnNetworkSpawnsAreNotPrevented() |
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.
These tests feel pretty rough in their current state.
- There are lots of magic numbers. There are even magic numbers that depend on other magic numbers (2, 3, and 5)
- You have 1 setup for 2 different tests. Is all the code in the setup necessary for both?
- You have log asserts in your test setup. Are these asserts actual tests, or are they an attempt to verify that setup has done what it's expected to?
- You are using the multi-instance tests and have a client but it's unclear if this is actually necessary for this test (don't these virtual methods get invoked on the server too? Can't you write a much simpler/more contained UnityTest that doesn't involve a client or waiting for frames with timeout asserts and
if (IsClient)
?) - It's unclear (to me) why you have
if (NumClientSpawns > 2)
guard in the test components.
While it's a very contentious topic, generally speaking, the more self-contained a test is, the better for understanding and lower the risk for future false positives. I'm not personally a fan of having to read 3 classes and 6 methods to understand what's actually happening in this 1 line test case.
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.
While throwing an exception in a component added to the player prefab is valid, I think this test should add more NetworkBehaviour derived components because the real test is to validate that all NetworkBehaviour components on a GameObject get OnNetworkSpawn and OnNetworkDespawn invoked even if one of the components throws and exception.
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.
I think I've addressed everything you mentioned here, except for the use of multi-instance tests. I think it's valuable to test that the behavior is the same on both server and client. I did, however, update the test to make sure it isn't exclusively a client-side test, since OnNetworkSpawn and OnNetworkDespawn are called on the server too.
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.
The included integration test only verifies that it throws an exception but does not verify that other components on the same GameObject still have their OnNetworkSpawn and OnNetworkDespawn method invoked when there are one or more NetworkBehaviour components on the GameObject and one of them throws an exception during the spawn/despawn periods.
Maybe adding an additional component after the one that throws an exception could be the verification that it was invoked after the NetworkBehaviour before it throws an exception?
# Conflicts: # com.unity.netcode.gameobjects/CHANGELOG.md
Also fixed merge issue with changelog.
# Conflicts: # com.unity.netcode.gameobjects/CHANGELOG.md # com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs
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.
Looks good to me kitty!
…ocessing of the next callback. [MTT-1378] (Unity-Technologies#1739) * fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback. * Standards and changelog. * Standards fixes * It would be good to check in the right file. * I swear these tests passed before but I have no idea how. Also review feedback. * Address review feedback. * Switched to LogAssert.Expect * Updated tests to NetcodeIntegrationTest style * Standards fix * Rewrote tests according to feedback. Also fixed merge issue with changelog. * Test the behavior on both server and client * style fixing white space issue. * Update com.unity.netcode.gameobjects/CHANGELOG.md Co-authored-by: Fatih Mar <[email protected]> Co-authored-by: Noel Stephens <[email protected]> Co-authored-by: Fatih Mar <[email protected]>
MTT-1378
Changelog
com.unity.netcode.gameobjects
Testing and Documentation