Skip to content

Commit 233d17c

Browse files
committed
Change: sustained invocations test in ActionDebouncerTests
1 parent fe76699 commit 233d17c

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

tests/Tests.CodeOfChaos.Extensions/Debouncers/ActionDebouncerTests.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,27 @@ public async Task InvocationDuringDebounce_ShouldCancelPrevious() {
143143
[Test]
144144
public async Task SustainedInvocations_ShouldExecuteEveryDebounceInterval() {
145145
// Arrange
146+
DateTime startTime = DateTime.UtcNow;
147+
var tasks = new List<Task>();
146148
List<DateTime> executionTimes = new();
147149
Action callback = () => { executionTimes.Add(DateTime.UtcNow); };
148150

149151
const int debounceMs = 100; // Define debounce interval
150-
const int totalDurationMs = 500; // Total time to sustain invocations
152+
const int totalDurationMs = 550; // Total time to sustain invocations
153+
const int expectedExecutions = totalDurationMs / debounceMs;
151154

152155
await using var debouncer = new ActionDebouncer(callback, debounceMs);
153-
154156
// Act
155-
var startTime = DateTime.UtcNow;
156-
var tasks = new List<Task>();
157157

158-
// Perform sustained invocations for `totalDurationMs`
159158
while ((DateTime.UtcNow - startTime).TotalMilliseconds < totalDurationMs) {
160159
tasks.Add(debouncer.InvokeDebouncedAsync());
161160
await Task.Delay(50); // Simulate frequent invocations faster than debounce interval
162161
}
163-
164-
// Wait just beyond the last debounce interval to ensure final execution
165-
await Task.Delay(debounceMs + 50);
162+
163+
await Task.Delay(debounceMs + 50); // Wait just beyond the last debounce interval to ensure final execution
166164

167165
// Assert
168166
await Task.WhenAll(tasks);
169-
const int expectedExecutions = totalDurationMs / debounceMs;
170167

171168
// Each execution should occur roughly at debounceMs intervals
172169
await Assert.That(executionTimes.Count).IsEqualTo((int)Math.Floor((double)expectedExecutions));

0 commit comments

Comments
 (0)