Skip to content

Update test method to fix test issue:47861 #49604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SimonZhao888
Copy link
Member

@SimonZhao888 SimonZhao888 commented Jun 30, 2025

Fix test issue: #47861

Root Cause

Throw an exception in the action delegate will stop the Retry method!
Referring to the ExecuteAsyncWithRetry method

public static async Task<T> ExecuteAsyncWithRetry<T>(Func<Task<T>> action,
    Func<T, bool> shouldStopRetry,
    int maxRetryCount,
    Func<IEnumerable<Task>> timer,
    string taskDescription = "")
{
    var count = 0;
    foreach (var t in timer())
    {
        await t;
        T result = default;
        count++;

        result = await action();

        if (shouldStopRetry(result))
        {
            return result;
        }

        if (count == maxRetryCount)
        {
            return result;
        }
    }
    throw new Exception("Timer should not be exhausted");
}

Whether or not to retry is only relevant to the expression in

await ExecuteAsyncWithRetry(action, result => result != null && !result.Equals(default), maxRetryCount, timer);

so consider modifying the test case to simulate failure retries.

Proposed changes

  • Update test case.

@Copilot Copilot AI review requested due to automatic review settings June 30, 2025 07:24
@SimonZhao888 SimonZhao888 requested a review from joeloff June 30, 2025 07:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the ItRetriesOnError test in GivenExponentialRetry.cs to simulate retry behavior via null results rather than thrown exceptions, and re-enables the test by removing its Skip attribute.

  • Removed the [Fact(Skip = ...)] attribute to run the test.
  • Changed the test action to return null instead of throwing an exception.
  • Updated assertions to expect a null result and verify retry count.
Comments suppressed due to low confidence (1)

test/dotnet.Tests/GivenExponentialRetry.cs:29

  • [nitpick] The test name 'ItRetriesOnError' suggests exception-based failures, but the updated test simulates a null result. Consider renaming it to something like 'ItRetriesOnNullResult' to better reflect its behavior.
        public async Task ItRetriesOnError()

@SimonZhao888 SimonZhao888 requested a review from MiYanni June 30, 2025 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant