-
Notifications
You must be signed in to change notification settings - Fork 28k
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
flutter_driver pauses all isolates at their startup (even ones started from compute()), rather than only pausing initial isolate #24703
Comments
Tests use https://pub.dartlang.org/packages/fake_async by default. Please consider asking support questions in one of the other channels listed at http://flutter.io/support . |
Thanks for the quick response. Keep the great work, Flutter is the first mobile framework I really enjoy working with. I have with 3 other frameworks in the past and it was rarely smooth as Flutter. |
Getting back to this issue (please let me know if I should move this to support). |
I tried to follow the examples you provide by wrapping my app with runAsync with the hope that the integration tests run smoothly, but the app doesn't even launch. I don't have time to run further tests at this time, so I will come back to this in a couple of weeks. Thanks for the help. |
@Hixie who might know if this is supposed to work? |
Could you give an example of how to wrap the app under test in runAsync ? |
This is what I tried: import 'package:flutter_driver/driver_extension.dart';
import 'package:flutter_test/flutter_test.dart';
import '../lib/my_app.dart';
void main() {
enableFlutterDriverExtension();
testWidgets(
'app test',
(WidgetTester tester) async {
final app = MyApp();
await tester.runAsync(() async {
await tester.pumpWidget(app);
await tester.idle();
});
}
);
} |
Generally driver tests are not expected to use flutter_test. The device side is expected to just be the app, and the driver side is expected to be a command-line app. Using |
Yes, I guessed that much, but just gave a shot. |
I am experiencing this as well in my application when attempting to test with the driver. My application loads assets at startup and ends up hanging on a call to The code is open source so I can share that but if it helps I'm happy to reproduce it in an isolated repo. |
Meanwhile using a workaround that probably doesn't suit for everybody's needs import 'package:flutter/foundation.dart' as flutter show compute;
import 'package:flutter/foundation.dart' show ComputeCallback;
Future<R> compute<Q, R>(ComputeCallback<Q, R> callback, Q message) async {
if (isInDebugMode) {
return callback(message);
}
return await flutter.compute(callback, message);
} |
I implemented a similar approach when trying to figure out why my tests were failing. It works, but it's far from perfect though because you're not testing your app as it will be shipped. It's acceptable if you have a couple of simple compute operations, but not so much when you have a lot more of those in critical places (like I currently have in many of my app API calls). |
Seems like there isn't any workaround for Isolate with async function because of #25890 |
@Hixie Hey, is anything planned to resolve this issue ? |
Hey @zoechi I think this issue should be added to the Goals milestone. It prevents me from adding integration tests to my which is really annoying for a production app. Thanks for your help! |
This is really annoying and came totally unexpected when using the screenshot package and the Future from Also, this can break basically anything, as we have no idea what calls the |
I would like to clarify, the problem appears when using Even when running the following code directly...
... the @eikob is absolutely right. It is only a matter of time when a particular package accidentally breaks the UI automation. If this behavior of |
Anynews on this issue ? |
After looking at the dart VM Observatory I found out, that the isolate is paused at start. When you manually start the isolate, it works perfectly. Maybe that helps figuring out the issue. |
When I try to run
It then hangs here indefinitely. Is this related? According to debug printing, it is hanging on group('Bottlepay app SkSL warmup', () {
FlutterDriver driver;
IsolatesWorkaround workaround;
// Connect to the Flutter driver before running any tests.
setUpAll(() async {
print('Connecting driver');
driver = await FlutterDriver.connect();
print('Driver connected');
if (driver.appIsolate.isPaused) {
print('Waiting for IsolatesWorkaround to resume isolates');
workaround = IsolatesWorkaround(driver);
await workaround.resumeIsolates();
print('Isolates resumed');
}
print('Waiting for first frame to rasterize');
await driver.waitUntilFirstFrameRasterized();
print('First frame rasterized');
});
// Close the connection to the driver after the tests have completed.
tearDownAll(() async {
if (driver != null) {
await driver.close();
await workaround?.tearDown();
}
}); I am unable to run driver tests on android for both a simulator and physical device because of this. On the simulator it freezes on |
I got back to this and reproduced the problem. I suspect https://github.com/flutter/gallery/blob/master/test_driver/isolates_workaround.dart is related. Maybe a conflict between the two fixes for the same bug? |
What do folks think of this approach to fixing the issue?
|
The gallery integration tests which are run from flutter/flutter are pinned to the commit in |
Looks like this is getting reverted again due to Google test failures, so re-opening. @speaking-in-code see also b/77244607 /cc @rmacnak-google since we were discussing this back in April 2018. At the time, we mused about the ability to send a command to the vm service saying "change the vm behavior such that we don't start new isolates paused anymore". |
@tvolkert Is this now really fixed in dev or was it again reverted? |
@HerrNiklasRaab this was re-landed and re-closed in #65703 (7a4d8e1), which was included in |
I have run into a situation that may be related. I have a 1.7MB json asset that I am loading as a string with I tried loading the string outside of a compute but that didn't resolve the issue. final data = await rootBundle.load(path);
final string = utf8.decode(data.buffer.asUint8List()); Is loading large string assets causing non-driver tests to hang indefinitely a known issue? EDIT: If I swap |
@lukepighetti yeah that sounds like it's related to this issue.
|
I'm using this wrapper to allow my own /// Because Isolates are started "paused" during tests (--start-paused) and don't execute at all, this function
/// wraps [compute] and executes the computation on the same [Isolate].
Future<R> testableCompute<Q, R>(ComputeCallback<Q, R> callback, Q message, {String? debugLabel}) async {
// During tests, don't start a new isolate, instead execute the computation on the same isolate
if (!kIsWeb && Platform.environment.containsKey('FLUTTER_TEST')) {
// fake Isolate.spawn delay
await Future.delayed(Duration(milliseconds: 500));
return await callback(message);
}
return await compute(callback, message, debugLabel: debugLabel);
} |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Isolates spawned using "compute" don't execute properly while executed in an integration test which in turn results in incorrect app behavior.
How to reproduce:
The app works properly when executing flutter run, but the integration test fails (flutter drive --target=test_driver/app.dart)
The text was updated successfully, but these errors were encountered: