Skip to content

Commit fe76699

Browse files
committed
Chore: Update TUnit to version 0.56.5 across projects and refine debouncer logic
Upgraded TUnit package in all projects to v0.56.5. Refined `DebouncerBase` logic to improve cancellation handling and adjusted invocation timing. Added a new debounce unit test for sustained invocations.
1 parent 565d6f8 commit fe76699

File tree

12 files changed

+55
-18
lines changed

12 files changed

+55
-18
lines changed

src/CodeOfChaos.Extensions/Debouncers/DebouncerBase.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public abstract class DebouncerBase<T>(int debounceMs) : IAsyncDisposable {
3030
// -----------------------------------------------------------------------------------------------------------------
3131
protected abstract ValueTask InvokeCallbackAsync(T item, CancellationToken ct = default);
3232

33+
// ReSharper disable once PossiblyMistakenUseOfCancellationToken
3334
protected async Task DebouncerLogicAsync(T? value = default, CancellationToken ct = default) {
3435
ObjectDisposedException.ThrowIf(_isDisposed, this);
3536

@@ -45,19 +46,18 @@ protected async Task DebouncerLogicAsync(T? value = default, CancellationToken c
4546
_cts = new CancellationTokenSource();
4647
CancellationTokenSource? localCts = _cts;
4748
CancellationToken debounceToken = localCts.Token;
48-
49-
DateTime now = DateTime.UtcNow;
50-
if (!((now - _lastInvokeTime).TotalMilliseconds >= debounceMs)) return;
5149

52-
_lastInvokeTime = now;
5350
_debounceTask = Task.Run(function: async () => {
5451
try {
5552
await Task.Delay(debounceMs, debounceToken);
56-
if (!debounceToken.IsCancellationRequested) {
5753

58-
// ReSharper disable once PossiblyMistakenUseOfCancellationToken
59-
await InvokeCallbackAsync(_latestValue!, ct);
60-
}
54+
if (debounceToken.IsCancellationRequested) return;
55+
56+
DateTime now = DateTime.UtcNow;
57+
if (!((now - _lastInvokeTime).TotalMilliseconds >= debounceMs)) return;
58+
59+
_lastInvokeTime = now;
60+
await InvokeCallbackAsync(_latestValue!, ct);
6161
}
6262
catch (OperationCanceledException) {
6363
// Ignore

tests/Tests.CodeOfChaos.Extensions.Analyzers/Tests.CodeOfChaos.Extensions.Analyzers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="CodeOfChaos.Testing.TUnit" Version="0.13.0" />
14-
<PackageReference Include="TUnit" Version="0.55.6" />
14+
<PackageReference Include="TUnit" Version="0.56.5" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

tests/Tests.CodeOfChaos.Extensions.AspNetCore.Components/Tests.CodeOfChaos.Extensions.AspNetCore.Components.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0" />
1616
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
1717
<PackageReference Include="Moq" Version="4.20.72"/>
18-
<PackageReference Include="TUnit" Version="0.55.6" />
18+
<PackageReference Include="TUnit" Version="0.56.5" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

tests/Tests.CodeOfChaos.Extensions.AspNetCore/Tests.CodeOfChaos.Extensions.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0" />
1515
<PackageReference Include="Moq" Version="4.20.72"/>
16-
<PackageReference Include="TUnit" Version="0.55.6" />
16+
<PackageReference Include="TUnit" Version="0.56.5" />
1717
<PackageReference Include="Bogus" Version="35.6.3" />
1818
</ItemGroup>
1919

tests/Tests.CodeOfChaos.Extensions.DependencyInjection.Generators/Tests.CodeOfChaos.Extensions.DependencyInjection.Generators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
2020
<PackageReference Include="Moq" Version="4.20.72"/>
2121
<PackageReference Include="System.Formats.Asn1" Version="9.0.8" />
22-
<PackageReference Include="TUnit" Version="0.55.6" />
22+
<PackageReference Include="TUnit" Version="0.56.5" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

tests/Tests.CodeOfChaos.Extensions.DependencyInjection/Tests.CodeOfChaos.Extensions.DependencyInjection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0" />
1616
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
1717
<PackageReference Include="Moq" Version="4.20.72"/>
18-
<PackageReference Include="TUnit" Version="0.55.6" />
18+
<PackageReference Include="TUnit" Version="0.56.5" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

tests/Tests.CodeOfChaos.Extensions.EntityFrameworkCore/Tests.CodeOfChaos.Extensions.EntityFrameworkCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0" />
1515
<PackageReference Include="Moq" Version="4.20.72"/>
16-
<PackageReference Include="TUnit" Version="0.55.6" />
16+
<PackageReference Include="TUnit" Version="0.56.5" />
1717
<PackageReference Include="Bogus" Version="35.6.3" />
1818
</ItemGroup>
1919

tests/Tests.CodeOfChaos.Extensions.FluentValidation/Tests.CodeOfChaos.Extensions.FluentValidation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0" />
1515
<PackageReference Include="Moq" Version="4.20.72"/>
16-
<PackageReference Include="TUnit" Version="0.55.6" />
16+
<PackageReference Include="TUnit" Version="0.56.5" />
1717
<PackageReference Include="Bogus" Version="35.6.3" />
1818
</ItemGroup>
1919

tests/Tests.CodeOfChaos.Extensions.ObjectPool/Tests.CodeOfChaos.Extensions.ObjectPool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ItemGroup>
1313
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0" />
1414
<PackageReference Include="Moq" Version="4.20.72"/>
15-
<PackageReference Include="TUnit" Version="0.55.6" />
15+
<PackageReference Include="TUnit" Version="0.56.5" />
1616
<PackageReference Include="Bogus" Version="35.6.3" />
1717
</ItemGroup>
1818

tests/Tests.CodeOfChaos.Extensions.Serilog/Tests.CodeOfChaos.Extensions.Serilog.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" Version="2025.2.0" />
1515
<PackageReference Include="Moq" Version="4.20.72"/>
16-
<PackageReference Include="TUnit" Version="0.55.6" />
16+
<PackageReference Include="TUnit" Version="0.56.5" />
1717
<PackageReference Include="Bogus" Version="35.6.3" />
1818
</ItemGroup>
1919

0 commit comments

Comments
 (0)