@@ -26,6 +26,7 @@ internal class DistributeObjectsTests : IntegrationTestWithApproximation
2626 private const int k_LateJoinClientCount = 4 ;
2727 protected override int NumberOfClients => 0 ;
2828
29+
2930 public DistributeObjectsTests ( ) : base ( HostOrServer . DAHost )
3031 {
3132 }
@@ -38,9 +39,13 @@ protected override IEnumerator OnSetup()
3839
3940 protected override void OnServerAndClientsCreated ( )
4041 {
41- var serverTransport = m_ServerNetworkManager . NetworkConfig . NetworkTransport as UnityTransport ;
42- // I hate having to add time to our tests, but in case a VM is running slow the disconnect timeout needs to be reasonably high
43- serverTransport . DisconnectTimeoutMS = 1000 ;
42+ if ( ! m_UseCmbService )
43+ {
44+ var serverTransport = m_ServerNetworkManager . NetworkConfig . NetworkTransport as UnityTransport ;
45+ // I hate having to add time to our tests, but in case a VM is running slow the disconnect timeout needs to be reasonably high
46+ serverTransport . DisconnectTimeoutMS = 1000 ;
47+ }
48+
4449 m_DistributeObject = CreateNetworkObjectPrefab ( "DisObject" ) ;
4550 m_DistributeObject . AddComponent < DistributeObjectsTestHelper > ( ) ;
4651 m_DistributeObject . AddComponent < DistributeTestTransform > ( ) ;
@@ -52,13 +57,6 @@ protected override void OnServerAndClientsCreated()
5257 base . OnServerAndClientsCreated ( ) ;
5358 }
5459
55- protected override IEnumerator OnServerAndClientsConnected ( )
56- {
57- m_ServerNetworkManager . SpawnManager . EnableDistributeLogging = m_EnableVerboseDebug ;
58- m_ServerNetworkManager . ConnectionManager . EnableDistributeLogging = m_EnableVerboseDebug ;
59- return base . OnServerAndClientsConnected ( ) ;
60- }
61-
6260 private NetworkObject m_ObjectToValidate ;
6361
6462 private bool ValidateObjectSpawnedOnAllClients ( )
@@ -67,17 +65,11 @@ private bool ValidateObjectSpawnedOnAllClients()
6765
6866 var networkObjectId = m_ObjectToValidate . NetworkObjectId ;
6967 var name = m_ObjectToValidate . name ;
70- if ( ! UseCMBService ( ) && ! m_ServerNetworkManager . SpawnManager . SpawnedObjects . ContainsKey ( networkObjectId ) )
68+ foreach ( var manager in m_NetworkManagers )
7169 {
72- m_ErrorLog . Append ( $ "Client-{ m_ServerNetworkManager . LocalClientId } has not spawned { name } !") ;
73- return false ;
74- }
75-
76- foreach ( var client in m_ClientNetworkManagers )
77- {
78- if ( ! client . SpawnManager . SpawnedObjects . ContainsKey ( networkObjectId ) )
70+ if ( ! manager . SpawnManager . SpawnedObjects . ContainsKey ( networkObjectId ) )
7971 {
80- m_ErrorLog . Append ( $ "Client-{ client . LocalClientId } has not spawned { name } !") ;
72+ m_ErrorLog . Append ( $ "Client-{ manager . LocalClientId } has not spawned { name } !") ;
8173 return false ;
8274 }
8375 }
@@ -89,7 +81,7 @@ private bool ValidateObjectSpawnedOnAllClients()
8981 private bool ValidateDistributedObjectsSpawned ( bool lateJoining )
9082 {
9183 m_ErrorLog . Clear ( ) ;
92- var hostId = m_ServerNetworkManager . LocalClientId ;
84+ var hostId = GetAuthorityNetworkManager ( ) . LocalClientId ;
9385 if ( ! DistributeObjectsTestHelper . DistributedObjects . ContainsKey ( hostId ) )
9486 {
9587 m_ErrorLog . AppendLine ( $ "[Client-{ hostId } ] Does not have an entry in the root of the { nameof ( DistributeObjectsTestHelper . DistributedObjects ) } table!") ;
@@ -106,11 +98,11 @@ private bool ValidateDistributedObjectsSpawned(bool lateJoining)
10698 var expected = 0 ;
10799 if ( lateJoining )
108100 {
109- expected = k_ObjectCount / ( m_ClientNetworkManagers . Count ( ) + 1 ) ;
101+ expected = k_ObjectCount / m_NetworkManagers . Length ;
110102 }
111103 else
112104 {
113- expected = k_ObjectCount / ( m_ClientNetworkManagers . Where ( ( c ) => c . IsConnectedClient ) . Count ( ) + 1 ) ;
105+ expected = k_ObjectCount / m_NetworkManagers . Count ( c => c . IsConnectedClient ) ;
114106 }
115107
116108 // It should theoretically be the expected or...
@@ -140,8 +132,8 @@ private bool ValidateDistributedObjectsSpawned(bool lateJoining)
140132 private bool ValidateOwnershipTablesMatch ( )
141133 {
142134 m_ErrorLog . Clear ( ) ;
143- var hostId = m_ServerNetworkManager . LocalClientId ;
144- var expectedEntries = m_ClientNetworkManagers . Where ( ( c ) => c . IsListening && c . IsConnectedClient ) . Count ( ) + 1 ;
135+ var hostId = GetAuthorityNetworkManager ( ) . LocalClientId ;
136+ var expectedEntries = m_NetworkManagers . Count ( c => c . IsListening && c . IsConnectedClient ) ;
145137 // Make sure all clients have an table created
146138 if ( DistributeObjectsTestHelper . DistributedObjects . Count < expectedEntries )
147139 {
@@ -160,7 +152,7 @@ private bool ValidateOwnershipTablesMatch()
160152 m_ErrorLog . AppendLine ( $ "[Client-{ hostId } ] Does not have a local an entry in the { nameof ( DistributeObjectsTestHelper . DistributedObjects ) } table!") ;
161153 return false ;
162154 }
163- var clients = m_ServerNetworkManager . ConnectedClientsIds . ToList ( ) ;
155+ var clients = GetAuthorityNetworkManager ( ) . ConnectedClientsIds . ToList ( ) ;
164156 clients . Remove ( 0 ) ;
165157
166158 // Cycle through each client's entry on the DAHost to run a comparison
@@ -206,9 +198,9 @@ private bool ValidateOwnershipTablesMatch()
206198 private bool ValidateTransformsMatch ( )
207199 {
208200 m_ErrorLog . Clear ( ) ;
209- var hostId = m_ServerNetworkManager . LocalClientId ;
201+ var hostId = GetAuthorityNetworkManager ( ) . LocalClientId ;
210202 var daHostEntries = DistributeObjectsTestHelper . DistributedObjects [ hostId ] ;
211- var clients = m_ServerNetworkManager . ConnectedClientsIds . ToList ( ) ;
203+ var clients = GetAuthorityNetworkManager ( ) . ConnectedClientsIds . ToList ( ) ;
212204 foreach ( var clientOwner in daHostEntries . Keys )
213205 {
214206 // Cycle through the owner's objects
@@ -238,16 +230,9 @@ private bool ValidateTransformsMatch()
238230 private bool SpawnCountsMatch ( )
239231 {
240232 var passed = true ;
241- var spawnCount = 0 ;
242233 m_ErrorLog . Clear ( ) ;
243- if ( ! UseCMBService ( ) )
244- {
245- spawnCount = m_ServerNetworkManager . SpawnManager . SpawnedObjects . Count ;
246- }
247- else
248- {
249- spawnCount = m_ClientNetworkManagers [ 0 ] . SpawnManager . SpawnedObjects . Count ;
250- }
234+
235+ var spawnCount = GetAuthorityNetworkManager ( ) . SpawnManager . SpawnedObjects . Count ;
251236 foreach ( var client in m_ClientNetworkManagers )
252237 {
253238 var clientCount = client . SpawnManager . SpawnedObjects . Count ;
@@ -272,7 +257,7 @@ public IEnumerator DistributeNetworkObjects()
272257 {
273258 for ( int i = 0 ; i < k_ObjectCount ; i ++ )
274259 {
275- SpawnObject ( m_DistributeObject , m_ServerNetworkManager ) ;
260+ SpawnObject ( m_DistributeObject , GetAuthorityNetworkManager ( ) ) ;
276261 }
277262
278263 // Validate NetworkObjects get redistributed properly when a client joins
@@ -321,8 +306,10 @@ public IEnumerator DistributeNetworkObjects()
321306 yield return WaitForConditionOrTimeOut ( ValidateTransformsMatch ) ;
322307 AssertOnTimeout ( $ "[Client-{ j + 1 } ][Transform Mismatch] { m_ErrorLog } ") ;
323308
324- // DANGO-TODO: Make this tied to verbose mode once we know the CMB Service integration works properly
325- DisplayOwnership ( ) ;
309+ if ( m_EnableVerboseDebug )
310+ {
311+ DisplayOwnership ( ) ;
312+ }
326313
327314 yield return WaitForConditionOrTimeOut ( SpawnCountsMatch ) ;
328315 AssertOnTimeout ( $ "[Spawn Count Mismatch] { m_ErrorLog } ") ;
@@ -332,8 +319,9 @@ public IEnumerator DistributeNetworkObjects()
332319 private void DisplayOwnership ( )
333320 {
334321 m_ErrorLog . Clear ( ) ;
335- var daHostEntries = DistributeObjectsTestHelper . DistributedObjects [ 0 ] ;
336322
323+ var authorityId = GetAuthorityNetworkManager ( ) . LocalClientId ;
324+ var daHostEntries = DistributeObjectsTestHelper . DistributedObjects [ authorityId ] ;
337325 foreach ( var entry in daHostEntries )
338326 {
339327 m_ErrorLog . AppendLine ( $ "[Client-{ entry . Key } ][Owned Objects: { entry . Value . Count } ]") ;
0 commit comments