-
Notifications
You must be signed in to change notification settings - Fork 450
fix: key not found exception when client never connects #1821
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
Merged
NoelStephensUnity
merged 5 commits into
develop
from
fix/nccbug-131-key-exception-when-client-never-connects
Mar 21, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
76 changes: 76 additions & 0 deletions
76
com.unity.netcode.gameobjects/Tests/Runtime/ClientFailsToConnectTest.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,76 @@ | ||
using System.Collections; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using UnityEngine.TestTools; | ||
using Unity.Netcode.TestHelpers.Runtime; | ||
#if UNITY_UNET_PRESENT | ||
using Unity.Netcode.Transports.UNET; | ||
#endif | ||
|
||
namespace Unity.Netcode.RuntimeTests | ||
{ | ||
public class ClientOnlyConnectionTests | ||
{ | ||
private NetworkManager m_ClientNetworkManager; | ||
private GameObject m_NetworkManagerGameObject; | ||
private WaitForSeconds m_DefaultWaitForTick = new WaitForSeconds(1.0f / 30); | ||
private bool m_WasDisconnected; | ||
private TimeoutHelper m_TimeoutHelper; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
m_WasDisconnected = false; | ||
m_NetworkManagerGameObject = new GameObject(); | ||
m_ClientNetworkManager = m_NetworkManagerGameObject.AddComponent<NetworkManager>(); | ||
m_ClientNetworkManager.NetworkConfig = new NetworkConfig(); | ||
#if UNITY_UNET_PRESENT | ||
m_TimeoutHelper = new TimeoutHelper(30); | ||
m_ClientNetworkManager.NetworkConfig.NetworkTransport = m_NetworkManagerGameObject.AddComponent<UNetTransport>(); | ||
#else | ||
// Default is 1000ms per connection attempt and 60 connection attempts (60s) | ||
// Currently there is no easy way to set these values other than in-editor | ||
m_TimeoutHelper = new TimeoutHelper(70); | ||
m_ClientNetworkManager.NetworkConfig.NetworkTransport = m_NetworkManagerGameObject.AddComponent<UnityTransport>(); | ||
#endif | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator ClientFailsToConnect() | ||
{ | ||
// Wait for the disconnected event | ||
m_ClientNetworkManager.OnClientDisconnectCallback += M_ClientNetworkManager_OnClientDisconnectCallback; | ||
|
||
// Only start the client (so it will timeout) | ||
m_ClientNetworkManager.StartClient(); | ||
|
||
#if !UNITY_UNET_PRESENT | ||
// Unity Transport throws an error when it times out | ||
LogAssert.Expect(LogType.Error, "Failed to connect to server."); | ||
#endif | ||
yield return NetcodeIntegrationTest.WaitForConditionOrTimeOut(() => m_WasDisconnected, m_TimeoutHelper); | ||
Assert.False(m_TimeoutHelper.TimedOut, "Timed out waiting for client to timeout waiting to connect!"); | ||
|
||
// Shutdown the client | ||
m_ClientNetworkManager.Shutdown(); | ||
|
||
// Wait for a tick | ||
yield return m_DefaultWaitForTick; | ||
} | ||
|
||
private void M_ClientNetworkManager_OnClientDisconnectCallback(ulong obj) | ||
{ | ||
m_WasDisconnected = true; | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
if (m_NetworkManagerGameObject != null) | ||
{ | ||
Object.DestroyImmediate(m_NetworkManagerGameObject); | ||
} | ||
} | ||
} | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
com.unity.netcode.gameobjects/Tests/Runtime/ClientFailsToConnectTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.