From afb6b7564f032a4b90a482b6b4cd2073fa216521 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 8 Jul 2025 13:28:46 -0500 Subject: [PATCH 1/3] Issue-124: Fix TaskExtensions.Delay not unwrapping AggregateExceptions on retry closes #124 SemVer:Patch --- src/TaskExtensions.cs | 29 +++++++++++++++++++++----- tests/unit/DelayTests.cs | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 tests/unit/DelayTests.cs diff --git a/src/TaskExtensions.cs b/src/TaskExtensions.cs index 3956a6d..dd19601 100644 --- a/src/TaskExtensions.cs +++ b/src/TaskExtensions.cs @@ -433,16 +433,35 @@ public static Task CatchWhen(this Task task, FuncCreates a cancellable task that completes after a specified time interval. + /// The task. + /// The time span to wait before completing the returned task, or to wait indefinitely. + /// A cancellation token to observe while waiting for the task to complete. + /// + /// represents a negative time interval other than . + /// + /// -or- + /// + /// The argument's property is greater than 4294967294 on .NET 6 and later versions, or Int32.MaxValue on all previous versions. + /// The task has been canceled. + /// The provided has already been disposed. + /// A task that represents the time delay. public static Task Delay( this Task task, TimeSpan delayInterval, CancellationToken cancellationToken = default ) => task.ContinueWith(continuationTask => - { - return Task.Delay(delayInterval, cancellationToken) - .ContinueWith(delayTask => continuationTask.Result); - }).Unwrap(); + { + return Task.Delay(delayInterval, cancellationToken) + .ContinueWith(_ => continuationTask.IsFaulted + ? Task.FromException(PotentiallyUnwindException(continuationTask.Exception!)) + : Task.FromResult(continuationTask.Result), + cancellationToken + ); + }, + cancellationToken + ).Unwrap().Unwrap(); /// /// Faults a with a provided . diff --git a/tests/unit/DelayTests.cs b/tests/unit/DelayTests.cs new file mode 100644 index 0000000..5477f83 --- /dev/null +++ b/tests/unit/DelayTests.cs @@ -0,0 +1,44 @@ +using System; +using System.Diagnostics; +using System.Threading.Tasks; +using RLC.TaskChaining; +using Xunit; + +namespace RLC.TaskChainingTests; + +public class DelayTests +{ + [Fact] + public async Task ItShouldWaitTheConfiguredTime() + { + Stopwatch testStopWatch = new(); + int testDelayTimeMilliseconds = 15; + + testStopWatch.Start(); + + await Task.FromResult(1).Delay(TimeSpan.FromMilliseconds(testDelayTimeMilliseconds)); + + testStopWatch.Stop(); + + Assert.True(testStopWatch.ElapsedMilliseconds >= testDelayTimeMilliseconds); + } + + [Fact] + public async Task ItShouldEnsureRetryExceptionsAreNotWrapped() + { + Func> testFunc = _ => Task.FromException(new RetryException(1, new ArgumentNullException())); + Exception? actualValue = null; + + try + { + await testFunc(1) + .Delay(TimeSpan.Zero); + } + catch (RetryException exception) + { + actualValue = exception.InnerException!; + } + + Assert.IsType(actualValue); + } +} \ No newline at end of file From 1bc76f46d7a01cf10aad2a83c0e23367531659a6 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 8 Jul 2025 13:34:29 -0500 Subject: [PATCH 2/3] Issue-126: Add xunit.runner.json to make tests run serially closes #126 SemVer:Minor --- tests/unit/xunit.runner.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/unit/xunit.runner.json diff --git a/tests/unit/xunit.runner.json b/tests/unit/xunit.runner.json new file mode 100644 index 0000000..19168cc --- /dev/null +++ b/tests/unit/xunit.runner.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "maxParallelThreads": 1, + "parallelizeAssembly": false, + "parallelizeTestCollections": false, + "shadowCopy": false +} \ No newline at end of file From a605f0b19ad266874f03183029ca266b81ebed15 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 8 Jul 2025 13:42:54 -0500 Subject: [PATCH 3/3] Version bump to 2.20.0 --- project-metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project-metadata.json b/project-metadata.json index 8198573..9fc2e6c 100644 --- a/project-metadata.json +++ b/project-metadata.json @@ -2,7 +2,7 @@ "name": "task-chaining", "description": "Extension methods to System.Threading.Task to allow Promise-like chaining", "title": "TaskChaining", - "version": "2.19.2", + "version": "2.20.0", "ciEnvironment": { "variables": [ {