-
Notifications
You must be signed in to change notification settings - Fork 213
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
tearDown is called before a test block completes when there are async errors #1512
Comments
cc @natebosch do you think the recent changes could have modified the behavior here? |
This is probably an existing problem for quite some time - I was able to reproduce this internally while synced to a release from ~1 year ago |
This is probably working as intended, but I would imagine we should be able to change it. What is the motivation for wanting the test to continue? The downside is that some tests that fail quickly today could fail much more slowly (with timeouts) if we always wait for the main body of a test to complete even if we know the test won't pass. |
Running tearDown before the test completes is likely to cause other errors in the test and mask the original failure? For instance it might kill processes or delete temp directories that the test is using. I think we probably should allow the test to continue and not run |
Context: I found this when looking into flutter/flutter#81521. This happens in flutter_test because it makes the assumption that void testWidgets(String description, Future<void> Function() callback) {
test(description, () {
bool inTest = true;
addTearDown(() => inTest = false);
return () async {
assert(inTest);
await callback();
await nothing();
// tearDown runs around here, setting inTest to false.
assert(inTest); // Throws AssertionError
// More omitted clean up...
}();
});
}
Future<void> nothing() async {} |
Fixes #1512 The test invoker tracks the work down by the test, both the callback bodies and the other work registered with the framework, and in the typical case waits for it to be complete before the test is considered done and the next work, like running teardowns, can resume. Previously, any error would immediately ignore all outstanding work. In the case of an unhandled async error, the test may still be using resources that will be cleaned up by the tear down. - Stop ignoring all outstanding work on any error. - Explicitly ignore outstanding work for a timeout. - More reliably decrement the outstanding work counter in a few situations where an exception from a test callback could cause it to be missed. Previously these errors would have also caused the outstanding work to be ignored, so it didn't matter if the decrement happened. Use a try/finally around callbacks which introduce their own outstanding work tracking zones. Use a try/catch/rethrow around the body for load suites (the platform work including the user `main` method). Using a try/finally for the LoadSuite case can cause the runner to be held open waiting for `main` to complete after a signal should have stopped tests.
Consider the following:
Output:
It would be expected that "tearDown is called" should be printed after "End of test":
await nothing();
in the example above is needed to cause this incorrect behavior.Versions:
The text was updated successfully, but these errors were encountered: