Skip to content

Commit ed33a62

Browse files
committed
Added more logging to StartedParentCanWaitForChildActionCompletion-test
1 parent 59a0e9d commit ed33a62

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/SuspensionTests.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,34 @@ async Task<string> (string param, Workflow workflow) =>
365365
});
366366

367367
var param = "hello world and universe";
368-
var result = await parent.Schedule(parentFunctionId.Instance.Value, param).Completion();
369-
result.ShouldBe(param.ToUpper());
368+
try
369+
{
370+
var result = await parent.Schedule(parentFunctionId.Instance.Value, param).Completion();
371+
result.ShouldBe(param.ToUpper());
372+
}
373+
catch (Exception ex)
374+
{
375+
var parentStatus = await store
376+
.GetFunction(parentFunctionId.ToStoredId(parent.StoredType))
377+
.SelectAsync(sf => new { Name = "Parent", Status = sf?.Status });
378+
var childrenStatus = await param
379+
.Split(" ")
380+
.Select((_, i) => store
381+
.GetFunction(new StoredId(child.StoredType, $"Child{i}".ToStoredInstance()))
382+
.SelectAsync(sf => new { Name = $"Child{i}", Status = sf?.Status })
383+
)
384+
.AwaitAll();
385+
386+
var statusStr = parentStatus.AsEnumerable()
387+
.Concat(childrenStatus)
388+
.Select(a => $"{a.Name}: {a.Status}")
389+
.JoinStrings(Environment.NewLine);
390+
391+
throw new TimeoutException(
392+
"FunctionStates: " + Environment.NewLine + statusStr,
393+
innerException: ex
394+
);
395+
}
370396

371397
unhandledExceptionHandler.ShouldNotHaveExceptions();
372398
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace Cleipnir.ResilientFunctions.Tests.Utils;
4+
5+
public static class EnumerableLinq
6+
{
7+
public static IEnumerable<T> AsEnumerable<T>(this T t) => [t];
8+
public static string JoinStrings(this IEnumerable<string> strings, string separator) => string.Join(separator, strings);
9+
}

Core/Cleipnir.ResilientFunctions.Tests/Utils/TaskLinq.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ public static Task<TOut> Map<TIn, TOut>(this Task<TIn> task, Func<TIn, TOut> f)
1212

1313
public static Task<List<T>> ToListAsync<T>(this Task<IEnumerable<T>> task)
1414
=> task.ContinueWith(t => t.Result.ToList());
15+
16+
public static async Task<List<T>> AwaitAll<T>(this IEnumerable<Task<T>> tasks)
17+
{
18+
var results = new List<T>();
19+
foreach (var task in tasks)
20+
results.Add(await task);
21+
22+
return results;
23+
}
1524

1625
public static Task<bool> AnyAsync<T>(this Task<IEnumerable<T>> task) => task.ContinueWith(t => t.Result.Any());
1726
public static Task<bool> AnyAsync<T>(this Task<IReadOnlyList<T>> task) => task.ContinueWith(t => t.Result.Any());

0 commit comments

Comments
 (0)