Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TUnit.Core/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ public async Task ReregisterTestWithArguments(object?[]? methodArguments = null,

public DateTimeOffset? TestEnd { get; set; }

public int CurrentRetryAttempt { get; internal set; }


public IEnumerable<TestContext> GetTests(Func<TestContext, bool> predicate)
{
Expand Down
6 changes: 4 additions & 2 deletions TUnit.Engine/Services/TestExecution/RetryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public static async Task ExecuteWithRetry(TestContext testContext, Func<Task> ac

for (var attempt = 0; attempt < maxRetries + 1; attempt++)
{
testContext.CurrentRetryAttempt = attempt;

try
{
await action();
Expand Down Expand Up @@ -42,13 +44,13 @@ private static async Task<bool> ShouldRetry(TestContext testContext, Exception e
{
return false;
}

if (testContext.RetryFunc == null)
{
// Default behavior: retry on any exception if within retry limit
return true;
}

return await testContext.RetryFunc(testContext, ex, attempt + 1).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ namespace
public .<.Artifact> Artifacts { get; }
public .CancellationToken CancellationToken { get; set; }
public .ClassHookContext ClassContext { get; }
public int CurrentRetryAttempt { get; }
public .<.TestDetails> Dependencies { get; }
public ? DisplayNameFormatter { get; set; }
public .TestContextEvents Events { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ namespace
public .<.Artifact> Artifacts { get; }
public .CancellationToken CancellationToken { get; set; }
public .ClassHookContext ClassContext { get; }
public int CurrentRetryAttempt { get; }
public .<.TestDetails> Dependencies { get; }
public ? DisplayNameFormatter { get; set; }
public .TestContextEvents Events { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@ namespace
public .<.Artifact> Artifacts { get; }
public .CancellationToken CancellationToken { get; set; }
public .ClassHookContext ClassContext { get; }
public int CurrentRetryAttempt { get; }
public .<.TestDetails> Dependencies { get; }
public ? DisplayNameFormatter { get; set; }
public .TestContextEvents Events { get; }
Expand Down
Loading