Skip to content

Commit d341cf6

Browse files
committed
Refactor: Add thread safety to FuncDebouncerTests by introducing lock for execution times
1 parent 633b06f commit d341cf6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tests/Tests.CodeOfChaos.Extensions/Debouncers/Regular/FuncDebouncerTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Tests.CodeOfChaos.Extensions.Debouncers.Regular;
1010
// ---------------------------------------------------------------------------------------------------------------------
1111
// ReSharper disable ConvertToLocalFunction
1212
public class FuncDebouncerTests {
13+
private Lock Lock { get; } = new();
14+
1315
[Test]
1416
public async Task DefaultDebounceMs_ShouldBe100() {
1517
// Arrange
@@ -128,7 +130,9 @@ public async Task InvocationDuringDebounce_ShouldCancelPrevious_Func() {
128130
// Arrange
129131
var executionTimes = new List<DateTime>();
130132
Func<Task> callback = () => {
131-
executionTimes.Add(DateTime.UtcNow);
133+
lock (Lock) {
134+
executionTimes.Add(DateTime.UtcNow);
135+
}
132136
return Task.CompletedTask;
133137
};
134138

0 commit comments

Comments
 (0)