-
Notifications
You must be signed in to change notification settings - Fork 463
fix: DA client connection flow #3459
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
Merged
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
55c71ff
fix: DA client connection flow
EmandM 62baf60
Fix whitespace issues
EmandM d8012d1
Move expected message to ConnectionApproved
EmandM f5671fa
Fix compilation errors
EmandM f3ea82c
Fix OnVerifyCanReceive
EmandM 65ceb5e
only send SynchronizeComplete to the rust
EmandM 94b4b85
remove duplicate peer connected callback
EmandM a093781
chore(deps): update dependency recipeengine.modules.wrench to 0.10.50…
unity-renovate[bot] 87854c4
chore(deps): update dependency recipeengine.modules.wrench to 0.11.1 …
unity-renovate[bot] 059660a
Fix whitespace error
EmandM dc3d313
Merge branch 'develop-2.0.0' of https://github.com/Unity-Technologies…
EmandM 3787865
Remove unnecessary changes
EmandM ba725da
Fix tests
EmandM 9726cf1
Add actual feature flag for this feature rather than piggybacking of …
EmandM 0cb0419
Remove test changes
EmandM 365adbb
Merge branch 'develop-2.0.0' of https://github.com/Unity-Technologies…
EmandM a4c4f37
Merge branch 'develop-2.0.0' into fix/mttb-12308/client-connection-flow
NoelStephensUnity d0e540a
Fix Connection deferred queue
EmandM 68288b7
Log warning on duplicate connection approved
EmandM faa197e
Remove commented out code and add entry to changelog
EmandM 01e8046
Merge branch 'develop-2.0.0' into fix/mttb-12308/client-connection-flow
NoelStephensUnity a200ebf
Merge develop-2.0.0 into fix/mttb-12308/client-connection-flow
netcode-ci-service a899bd6
Merge develop-2.0.0 into fix/mttb-12308/client-connection-flow
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
244 changes: 244 additions & 0 deletions
244
testproject/Assets/Tests/Runtime/NetworkSceneManager/SceneManagementSynchronizationTests.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,244 @@ | ||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using NUnit.Framework; | ||
| using Unity.Collections; | ||
| using Unity.Netcode; | ||
| using Unity.Netcode.TestHelpers.Runtime; | ||
| using UnityEngine.TestTools; | ||
|
|
||
| namespace TestProject.RuntimeTests | ||
| { | ||
| [TestFixture(HostOrServer.Host)] | ||
| [TestFixture(HostOrServer.Server)] | ||
| [TestFixture(HostOrServer.DAHost)] | ||
| public class SceneManagementSynchronizationTests : NetcodeIntegrationTest | ||
| { | ||
| protected override int NumberOfClients => 1; | ||
|
|
||
|
|
||
| public SceneManagementSynchronizationTests(HostOrServer hostOrServer) : base(hostOrServer) | ||
| { | ||
| } | ||
|
|
||
| private struct ExpectedEvent | ||
| { | ||
| public SceneEvent SceneEvent; | ||
| public ConnectionEventData ConnectionEvent; | ||
| } | ||
|
|
||
| private readonly Queue<ExpectedEvent> m_ExpectedEventQueue = new(); | ||
|
|
||
| private static int s_NumEventsProcessed; | ||
|
|
||
| private void OnSceneEvent(SceneEvent sceneEvent) | ||
| { | ||
| VerboseDebug($"OnSceneEvent! Type: {sceneEvent.SceneEventType}."); | ||
| AssertEventMatchesExpectedEvent(expectedEvent => | ||
| ValidateSceneEventsAreEqual(expectedEvent, sceneEvent), sceneEvent.SceneEventType); | ||
| } | ||
|
|
||
| private void OnConnectionEvent(NetworkManager manager, ConnectionEventData eventData) | ||
| { | ||
| VerboseDebug($"OnConnectionEvent! Type: {eventData.EventType} - Client-{eventData.ClientId}"); | ||
| AssertEventMatchesExpectedEvent(expectedEvent => | ||
| ValidateConnectionEventsAreEqual(expectedEvent, eventData), eventData.EventType); | ||
| } | ||
|
|
||
| private void AssertEventMatchesExpectedEvent<T>(Action<ExpectedEvent> predicate, T eventType) | ||
| { | ||
| if (m_ExpectedEventQueue.Count > 0) | ||
| { | ||
| var expectedEvent = m_ExpectedEventQueue.Dequeue(); | ||
| predicate(expectedEvent); | ||
| } | ||
| else | ||
| { | ||
| Assert.Fail($"Received unexpected event at index {s_NumEventsProcessed}: {eventType}"); | ||
| } | ||
|
|
||
| s_NumEventsProcessed++; | ||
| } | ||
|
|
||
| private NetworkManager m_ManagerToTest; | ||
|
|
||
| private void SetManagerToTest(NetworkManager manager) | ||
| { | ||
| m_ManagerToTest = manager; | ||
| m_ManagerToTest.OnConnectionEvent += OnConnectionEvent; | ||
| m_ManagerToTest.SceneManager.OnSceneEvent += OnSceneEvent; | ||
| } | ||
|
|
||
| protected override void OnNewClientStarted(NetworkManager networkManager) | ||
| { | ||
| // If m_ManagerToTest isn't set at this point, it means we are testing the newly created NetworkManager | ||
| if (m_ManagerToTest == null) | ||
| { | ||
| SetManagerToTest(networkManager); | ||
| } | ||
| base.OnNewClientCreated(networkManager); | ||
| } | ||
|
|
||
| protected override IEnumerator OnTearDown() | ||
| { | ||
| m_ManagerToTest.OnConnectionEvent -= OnConnectionEvent; | ||
| m_ManagerToTest.SceneManager.OnSceneEvent -= OnSceneEvent; | ||
| m_ManagerToTest = null; | ||
| m_ExpectedEventQueue.Clear(); | ||
| s_NumEventsProcessed = 0; | ||
|
|
||
| yield return base.OnTearDown(); | ||
| } | ||
|
|
||
| [UnityTest] | ||
| public IEnumerator SynchronizationCallbacks_Authority() | ||
| { | ||
| SetManagerToTest(GetAuthorityNetworkManager()); | ||
|
|
||
| // Calculate the expected ID of the newly connecting networkManager | ||
| var expectedClientId = GetNonAuthorityNetworkManager().LocalClientId + 1; | ||
|
|
||
| // Setup expected events | ||
| m_ExpectedEventQueue.Enqueue(new ExpectedEvent() | ||
| { | ||
| SceneEvent = new SceneEvent() | ||
| { | ||
| SceneEventType = SceneEventType.Synchronize, | ||
| ClientId = expectedClientId | ||
| }, | ||
| }); | ||
|
|
||
| m_ExpectedEventQueue.Enqueue(new ExpectedEvent() | ||
| { | ||
| SceneEvent = new SceneEvent() | ||
| { | ||
| SceneEventType = SceneEventType.SynchronizeComplete, | ||
| ClientId = expectedClientId, | ||
| }, | ||
| }); | ||
|
|
||
| m_ExpectedEventQueue.Enqueue(new ExpectedEvent() | ||
| { | ||
| ConnectionEvent = new ConnectionEventData() | ||
| { | ||
| EventType = ConnectionEvent.ClientConnected, | ||
| ClientId = expectedClientId, | ||
| } | ||
| }); | ||
|
|
||
| if (m_UseHost) | ||
| { | ||
| m_ExpectedEventQueue.Enqueue(new ExpectedEvent() | ||
| { | ||
| ConnectionEvent = new ConnectionEventData() | ||
| { | ||
| EventType = ConnectionEvent.PeerConnected, | ||
| ClientId = expectedClientId, | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| m_EnableVerboseDebug = true; | ||
| ////////////////////////////////////////// | ||
| // Testing event notifications | ||
| yield return CreateAndStartNewClient(); | ||
| yield return null; | ||
|
|
||
| Assert.IsEmpty(m_ExpectedEventQueue, "Not all expected callbacks were received"); | ||
| } | ||
|
|
||
| [UnityTest] | ||
| public IEnumerator SynchronizationCallbacks_NonAuthority() | ||
| { | ||
| var authorityId = GetAuthorityNetworkManager().LocalClientId; | ||
| var peerClientId = GetNonAuthorityNetworkManager().LocalClientId; | ||
| var expectedClientId = peerClientId + 1; | ||
|
|
||
| var expectedPeerClientIds = m_UseHost ? new[] { authorityId, peerClientId } : new[] { peerClientId }; | ||
|
|
||
| // Setup expected events | ||
| m_ExpectedEventQueue.Enqueue(new ExpectedEvent() | ||
| { | ||
| ConnectionEvent = new ConnectionEventData() | ||
| { | ||
| EventType = ConnectionEvent.ClientConnected, | ||
| ClientId = expectedClientId, | ||
| PeerClientIds = new NativeArray<ulong>(expectedPeerClientIds.ToArray(), Allocator.Persistent), | ||
| } | ||
| }); | ||
|
|
||
| m_ExpectedEventQueue.Enqueue(new ExpectedEvent() | ||
| { | ||
| SceneEvent = new SceneEvent() | ||
| { | ||
| SceneEventType = SceneEventType.SynchronizeComplete, | ||
| ClientId = expectedClientId, | ||
| }, | ||
| }); | ||
|
|
||
| Assert.Null(m_ManagerToTest, "m_ManagerToTest should be null as we should be testing newly created client"); | ||
|
|
||
| ////////////////////////////////////////// | ||
| // Testing event notifications | ||
|
|
||
| // CreateAndStartNewClient will configure m_ManagerToTest inside OnNewClientStarted | ||
| yield return CreateAndStartNewClient(); | ||
| yield return null; | ||
|
|
||
| Assert.IsEmpty(m_ExpectedEventQueue, "Not all expected callbacks were received"); | ||
| } | ||
|
|
||
| [UnityTest] | ||
| public IEnumerator LateJoiningClient_PeerCallbacks() | ||
| { | ||
| SetManagerToTest(GetNonAuthorityNetworkManager()); | ||
| // Setup expected events | ||
| m_ExpectedEventQueue.Enqueue(new ExpectedEvent() | ||
| { | ||
| ConnectionEvent = new ConnectionEventData() | ||
| { | ||
| EventType = ConnectionEvent.PeerConnected, | ||
| ClientId = m_ManagerToTest.LocalClientId + 1, | ||
| } | ||
| }); | ||
|
|
||
| ////////////////////////////////////////// | ||
| // Testing event notifications | ||
| yield return CreateAndStartNewClient(); | ||
| yield return null; | ||
|
|
||
| Assert.IsEmpty(m_ExpectedEventQueue, "Not all expected callbacks were received"); | ||
| } | ||
|
|
||
| private static void ValidateSceneEventsAreEqual(ExpectedEvent expectedEvent, SceneEvent sceneEvent) | ||
| { | ||
| Assert.NotNull(expectedEvent.SceneEvent, $"Received unexpected scene event {sceneEvent.SceneEventType} at index {s_NumEventsProcessed}"); | ||
| AssertField(expectedEvent.SceneEvent.SceneEventType, sceneEvent.SceneEventType, nameof(sceneEvent.SceneEventType), sceneEvent.SceneEventType); | ||
| AssertField(expectedEvent.SceneEvent.ClientId, sceneEvent.ClientId, nameof(sceneEvent.ClientId), sceneEvent.SceneEventType); | ||
| } | ||
|
|
||
| private static void ValidateConnectionEventsAreEqual(ExpectedEvent expectedEvent, ConnectionEventData eventData) | ||
| { | ||
| Assert.NotNull(expectedEvent.ConnectionEvent, $"Received unexpected connection event {eventData.EventType} at index {s_NumEventsProcessed}"); | ||
| AssertField(expectedEvent.ConnectionEvent.EventType, eventData.EventType, nameof(eventData.EventType), eventData.EventType); | ||
| AssertField(expectedEvent.ConnectionEvent.ClientId, eventData.ClientId, nameof(eventData.ClientId), eventData.EventType); | ||
|
|
||
| AssertField(expectedEvent.ConnectionEvent.PeerClientIds.Length, eventData.PeerClientIds.Length, "length of PeerClientIds", eventData.EventType); | ||
| if (eventData.PeerClientIds.Length > 0) | ||
| { | ||
| var peerIds = eventData.PeerClientIds.ToArray(); | ||
| foreach (var expectedClientId in expectedEvent.ConnectionEvent.PeerClientIds) | ||
| { | ||
| Assert.Contains(expectedClientId, peerIds, "PeerClientIds does not contain all expected client IDs."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void AssertField<T, TK>(T expected, T actual, string fieldName, TK type) | ||
| { | ||
| Assert.AreEqual(expected, actual, $"Failed on event {s_NumEventsProcessed} - {type}. Incorrect {fieldName}"); | ||
| } | ||
|
|
||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
...ject/Assets/Tests/Runtime/NetworkSceneManager/SceneManagementSynchronizationTests.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.