profile
viewpoint

Ask questionsflutter_driver pauses all isolates at their startup (even ones started from compute()), rather than only pausing initial isolate

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:

  • use example from https://flutter.io/docs/cookbook/testing/integration
  • in lib/main.dart
  1. add:
import 'package:flutter/foundation.dart';
  1. add function:
String _test(String s) {
  return s;
}
  1. modify _incrementCounter function:
  void _incrementCounter() async {
    final s = await compute(_test, 'hello');
    print(s);

    setState(() {
      _counter++;
    });
  }

The app works properly when executing flutter run, but the integration test fails (flutter drive --target=test_driver/app.dart)

flutter/flutter

Answer questions acoutts

When I try to run flutter drive --target=test_driver/app.dart --flavor sandbox -d 9A311FFAZ00C03 --profile --cache-sksl --write-sksl-on-exit sksl_cache/android.sksl.json on android, the test never runs. The app is installed and the splash screen shows but the dart isolate never starts.

...
Running Gradle task 'assembleSandboxProfile'... Done              109.4s
✓ Built build/app/outputs/flutter-apk/app-sandbox-profile.apk (65.7MB).
Installing build/app/outputs/flutter-apk/app.apk...                 5.1s
I/flutter (26379): Observatory listening on http://127.0.0.1:39715/yP9wvTmO1Pw=/
00:00 +0: Bottlepay app SkSL warmup (setUpAll)

Connecting driver

VMServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:62204/yP9wvTmO1Pw=/
VMServiceFlutterDriver: Isolate found with number: 3846210052022527
VMServiceFlutterDriver: Unknown pause event type VMNoneEvent. Assuming application is ready.
E/FlutterFcmService(26379): Fatal: failed to find callback
VMServiceFlutterDriver: Flutter Driver extension is taking a long time to become available. Ensure your test app (often "lib/main.dart") imports "package:flutter_driver/driver_extension.dart" and calls enableFlutterDriverExtension() as the first call in main().

It then hangs here indefinitely. Is this related?

According to debug printing, it is hanging on driver = await FlutterDriver.connect();.

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 await driver.waitUntilFirstFrameRasterized();.

useful!
source:https://uonfu.com/
Github User Rank List