Skip to content

Commit a40f555

Browse files
committed
test: adding tests to makle sure no attribute means no rate limit
1 parent 203de40 commit a40f555

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Assets/Tests/Runtime/RateLimit/RpcRateLimitTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public UniTask<int> AsyncServerRpcWithRateLimit()
3333
AsyncCount++;
3434
return UniTask.FromResult(AsyncCount);
3535
}
36+
37+
public int UnattributedCount;
38+
39+
[ServerRpc(requireAuthority = false)]
40+
public void UnattributedRpc()
41+
{
42+
UnattributedCount++;
43+
}
3644
}
3745

3846
public class RpcRateLimitTests : ClientServerSetup<RpcRateLimitBehaviour>
@@ -173,6 +181,20 @@ public IEnumerator RpcDoesNotRefillBeforeInterval() => UniTask.ToCoroutine(async
173181

174182
Assert.That(serverComponent.Count, Is.EqualTo(2), "Call should be dropped because interval hasn't accumulated enough time for a refill");
175183
});
184+
185+
[UnityTest]
186+
public IEnumerator RpcWithoutAttributeIsNotRateLimited() => UniTask.ToCoroutine(async () =>
187+
{
188+
for (int i = 0; i < 1000; i++)
189+
{
190+
clientComponent.UnattributedRpc();
191+
}
192+
193+
await UniTask.Delay(100); // adjust delay if needed
194+
195+
Assert.That(serverComponent.UnattributedCount, Is.EqualTo(1000), "RPC without attribute should not be rate limited");
196+
Assert.That(serverPlayer.ErrorFlags, Is.Not.EqualTo(PlayerErrorFlags.RateLimit));
197+
});
176198
}
177199

178200
public class RpcRateLimitHostTests : HostSetup<RpcRateLimitBehaviour>

0 commit comments

Comments
 (0)