Skip to content

Commit 553a27d

Browse files
committed
test: replace manual tests with automated tests (#1365)
- C788903 Verify null arrays of custom types are being serialized - C788904 Verify RpcDelivery option exposed on both ServerRpc and ClientRpc attributes - C788905 Verify RpcDelivery options are mapping to matching transport channels for replication - C788906 Verify when RpcDelivery is not specified that Rpc still replicates - C788912 Verify ServerRpc method with no parameters replicates from client to server - C788913 Verify ClientRpc method with no parameters replicates from server to 1 client - C788915 Verify ServerRpc method with 1 parameter replicates from client to server - C788916 Verify ClientRpc method with 1 parameter replicates from server to 1 client - C788918 Verify ServerRpc method with more than 1 parameters replicates from client to server - C788919 Verify ClientRpc method with more than 1 parameters replicates from server to 1 client - C788921 Verify C# and Unity primitive types are supported in Rpc method signatures - C816309 Verify that sending Rpc messages are sent and received properly through the queue system - C816312 Verifies the core functionality of the RcpQueueContainer
1 parent fe158c3 commit 553a27d

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

com.unity.netcode.gameobjects/Tests/Runtime/RpcOwnershipCustomTests.cs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ public class RpcOwnershipObject : NetworkBehaviour
7373
public int RequireOwnershipCount = 0;
7474
public int DoesntRequireOwnershipCount = 0;
7575
public int ArrayRpcCount = 0;
76+
public bool ReliableServerRpcCalled;
77+
public bool ReliableClientRpcCalled;
78+
public bool UnreliableServerRpcCalled;
79+
public bool UnreliableClientRpcCalled;
80+
81+
[ServerRpc]
82+
public void ExpectingNullObjectServerRpc(CustomType anObject)
83+
{
84+
Debug.Assert(anObject == null);
85+
}
7686

7787
[ServerRpc(RequireOwnership = true)]
7888
public void RequireOwnershipServerRpc()
@@ -98,7 +108,7 @@ public void TwoCustomTypesAndVect3ServerRpc(CustomType someObject, DifferentCust
98108
}
99109

100110
[ServerRpc]
101-
public void ArrayOfCustomTypesServerRpc(CustomType[] arrayOfObjects, CustomType[] emptyArray)
111+
public void ArrayOfCustomTypesServerRpc(CustomType[] arrayOfObjects, CustomType[] emptyArray, CustomType[] nullArray)
102112
{
103113
Debug.Assert(arrayOfObjects.Length > 0);
104114
for (int i = 0; i < arrayOfObjects.Length; i++)
@@ -110,9 +120,31 @@ public void ArrayOfCustomTypesServerRpc(CustomType[] arrayOfObjects, CustomType[
110120
}
111121

112122
Debug.Assert(emptyArray.Length == 0);
123+
Debug.Assert(nullArray == null);
113124

114125
ArrayRpcCount++;
115126
}
127+
128+
[ServerRpc(Delivery = RpcDelivery.Unreliable)]
129+
public void UnreliableServerRpc()
130+
{
131+
UnreliableServerRpcCalled = true;
132+
}
133+
[ServerRpc(Delivery = RpcDelivery.Reliable)]
134+
public void ReliableServerRpc()
135+
{
136+
ReliableServerRpcCalled = true;
137+
}
138+
[ClientRpc(Delivery = RpcDelivery.Unreliable)]
139+
public void UnreliableClientRpc()
140+
{
141+
UnreliableClientRpcCalled = true;
142+
}
143+
[ClientRpc(Delivery = RpcDelivery.Reliable)]
144+
public void ReliableClientRpc()
145+
{
146+
ReliableClientRpcCalled = true;
147+
}
116148
}
117149

118150
public class RpcOwnershipCustomTests : BaseMultiInstanceTest
@@ -166,13 +198,15 @@ public IEnumerator RpcArrayCustomTypesTest()
166198

167199
netSpawnedObject.Spawn();
168200

201+
netSpawnedObject.GetComponent<RpcOwnershipObject>().ExpectingNullObjectServerRpc(null);
202+
169203
var arrayOfObjects = new CustomType[2] { new CustomType(), new CustomType() };
170204
var emptyArray = new CustomType[0];
171205

172206
arrayOfObjects[0].SomeValue = 1;
173207
arrayOfObjects[1].SomeValue = 2;
174208

175-
netSpawnedObject.GetComponent<RpcOwnershipObject>().ArrayOfCustomTypesServerRpc(arrayOfObjects, emptyArray);
209+
netSpawnedObject.GetComponent<RpcOwnershipObject>().ArrayOfCustomTypesServerRpc(arrayOfObjects, emptyArray, null);
176210

177211
Debug.Assert(netSpawnedObject.GetComponent<RpcOwnershipObject>().ArrayRpcCount == 1);
178212
yield return null;
@@ -196,6 +230,38 @@ public IEnumerator CustomTypesTest()
196230
yield return null;
197231
}
198232

233+
[UnityTest]
234+
public IEnumerator RpcDeliveryTests()
235+
{
236+
var spawnedObject = UnityEngine.Object.Instantiate(m_PrefabToSpawn);
237+
var netSpawnedObject = spawnedObject.GetComponent<NetworkObject>();
238+
netSpawnedObject.NetworkManagerOwner = m_ServerNetworkManager;
239+
240+
var rpcObject = spawnedObject.GetComponent<RpcOwnershipObject>();
241+
242+
netSpawnedObject.Spawn();
243+
244+
rpcObject.ReliableServerRpc();
245+
rpcObject.ReliableClientRpc();
246+
247+
// Those two calls are unreliable. So, for testing, we'll call them multiple
248+
// times (just one call might be dropped). If it so happens that 10 calls in a row are missed, then some
249+
// debugging would be worth.
250+
for (int i = 0; i < 10; i++)
251+
{
252+
rpcObject.UnreliableServerRpc();
253+
rpcObject.UnreliableClientRpc();
254+
255+
var nextFrameNumber = Time.frameCount + 1;
256+
yield return new WaitUntil(() => Time.frameCount >= nextFrameNumber);
257+
}
258+
259+
Debug.Assert(rpcObject.ReliableServerRpcCalled);
260+
Debug.Assert(rpcObject.UnreliableServerRpcCalled);
261+
Debug.Assert(rpcObject.ReliableClientRpcCalled);
262+
Debug.Assert(rpcObject.UnreliableClientRpcCalled);
263+
}
264+
199265
private IEnumerator RunTests(bool serverOwned)
200266
{
201267
m_ExpectedRequireOwnershipCount = 0;

0 commit comments

Comments
 (0)