From 77d16861938c5d2ca6a2874828e5d10540ae7c98 Mon Sep 17 00:00:00 2001 From: Bobby Galli Date: Thu, 29 May 2025 19:09:35 -0400 Subject: [PATCH] Add rate limit tests for ShouldPostExceptionImpl --- .../Util/ShouldPostExceptionImplTests.cs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Tests/Runtime/Util/ShouldPostExceptionImplTests.cs b/Tests/Runtime/Util/ShouldPostExceptionImplTests.cs index ca937f4..f2e4ac2 100644 --- a/Tests/Runtime/Util/ShouldPostExceptionImplTests.cs +++ b/Tests/Runtime/Util/ShouldPostExceptionImplTests.cs @@ -1,13 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using BugSplatUnity.Runtime.Util; +using NUnit.Framework; +using System; +using System.Reflection; +using System.Threading; namespace BugSplatUnity.RuntimeTests.Util { class ShouldPostExceptionImplTests { - // TODO + [Test] + public void DefaultShouldPostExceptionImpl_ShouldRespectRateLimiting() + { + // Reset internal lastPost field to ensure test independence + var field = typeof(ShouldPostExceptionImpl).GetField("lastPost", BindingFlags.NonPublic | BindingFlags.Static); + field.SetValue(null, new DateTime(0)); + + // First call should be allowed + Assert.IsTrue(ShouldPostExceptionImpl.DefaultShouldPostExceptionImpl()); + + // Second immediate call should be blocked + Assert.IsFalse(ShouldPostExceptionImpl.DefaultShouldPostExceptionImpl()); + + // After waiting for 3 seconds a subsequent call should be allowed + Thread.Sleep(TimeSpan.FromSeconds(3)); + Assert.IsTrue(ShouldPostExceptionImpl.DefaultShouldPostExceptionImpl()); + } } }