Skip to content
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

Handle synchronous TestFailure within async fn body #40

Merged

Conversation

aaronlademann-wf
Copy link
Contributor

@aaronlademann-wf aaronlademann-wf commented Nov 5, 2021

Motivation

@josephnaberhaus-wk pointed out that when the async modifier is added to the waitFor callback, any expect() within the callback that fails will cause waitFor to throw immediately instead of continuing to call the callback on an interval.

Essentially - the issue is that currently, the first test will fail immediately instead of waiting for numRuns to get to 5, whereas the second test will pass since it's not async.

test('this will fail as a result of the async modifier on the callback', () async {
  var numRuns = 0;
  await rtl.waitFor(() async {
    numRuns++;
    expect(numRuns, 5);
  });
});

test('this will pass', () async {
  var numRuns = 0;
  await rtl.waitFor(() {
    numRuns++;
    expect(numRuns, 5);
  });
});

@greglittlefield-wf @joebingham-wk @sydneyjodon-wk I am unsure if handling synchronous failures like this is desired behavior, but I am putting up this PR since I was able to get something working that seems to also preserve the existing behaviors of waiting for things like one of RTL's async matchers (findBy*).

Changes

Only call onDone() when the error thrown from the async function is not a TestFailure. If it is a TestFailure, store that failure as the lastError like we do when an error is thrown from a synchronous callback, and keep trying the callback until a timeout occurs.

These changes make it so that both of the test cases shown above will pass as expected.

Release Notes

Add support for synchronous test failures within an asynchronous callback in the waitFor utility.

@aviary-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

@aaronlademann-wf aaronlademann-wf force-pushed the improve-waitfor-async-not-really-async-behavior branch from 4c68ac2 to 556698d Compare November 5, 2021 13:45
@aaronlademann-wf aaronlademann-wf marked this pull request as ready for review November 5, 2021 13:55
@aaronlademann-wf aaronlademann-wf added enhancement New feature or request semver: Patch labels Nov 5, 2021
Align waitFor implementation more closely with JS implementation
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

+10

semver +1

@aaronlademann-wf
Copy link
Contributor Author

@Workiva/release-management-pp

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

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

+1 from RM

@rmconsole2-wf rmconsole2-wf merged commit e4fe4f2 into master Nov 5, 2021
@rmconsole2-wf rmconsole2-wf deleted the improve-waitfor-async-not-really-async-behavior branch November 5, 2021 19:00
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.

5 participants