dart_emulators icon indicating copy to clipboard operation
dart_emulators copied to clipboard

`emu.forEach` only working with one device

Open martin-braun opened this issue 11 months ago • 4 comments

@tim-smart you really did a great job here. We plan to mass produce white-labeled apps by branding them in a CI/CD pipeline. Obviously, we can't automate everything (App Store Connect / Google Play Console), but your work will cut times significantly for us.

However, experimenting with your demo project https://github.com/tim-smart/flutter-emulators-screenshots-demo has shown some issues that I had to circumvent:

I can't run emu.forEach with a bunch of named Android and iPhone emulators, i.e.: 'Pixel_7_Development_', 'iPhone Xs Max', .... The first emulator will start and make its screenshot, the second will not.

As a result, I call emu.forEach only with one device name and put everything in a loop to iterate my devices, which works like charm, but I assume it takes much longer than it should be.

Can I somehow provide you with some details to track down the issue? What could be the reasoning for it not to work properly?

Thanks! :)

martin-braun avatar Jul 15 '23 11:07 martin-braun

Once the first device is finished, what happens? Does it shutdown? Any errors?

It is supposed to shutdown the first device after it is finished then boot up the next device in the list.

tim-smart avatar Jul 16 '23 02:07 tim-smart

@tim-smart The first device shuts down, the second doesn't start, no errors, it just hangs somewhere.

martin-braun avatar Jul 16 '23 05:07 martin-braun

It sounds like the shutdown command is hanging.

Will add a timeout and see if that changes anything.

tim-smart avatar Jul 16 '23 05:07 tim-smart

I have the same behavior with more or less the same code that the demo project (see after). The only difference with @martin-braun's case is that the second iteration is triggered by the inner loop (on configs). That would rule out a bug specific to forEach but the result is the same: hanging on second launch.

The log part where the hanging happens:

...
VMServiceFlutterDriver: waitForCondition message is taking a long time to complete...
12:00 +0 -1: (setUpAll) [E]

  TimeoutException after 0:12:00.000000: Test timed out after 12 minutes.
...

The code of setUpAll for the test:

  setUpAll(() async {
    await driver.waitUntilFirstFrameRasterized();
    await screenshots.cleanStatusBar();
  });

And finally the code of the command:

import 'dart:io';
import 'package:emulators/emulators.dart';

Future<void> main() async {
  const List<String> emulatorIds = [
    'iPhone 15',
  ];
  const configs = [
    {'locale': 'en-GB'},
    {'locale': 'fr-FR'},
  ];

  final emulators = await Emulators.build();
  await emulators.shutdownAll();
  await emulators.forEach(emulatorIds)((device) async {
    for (final c in configs) {
      final proc = await emulators.drive(
        device,
        'test_driver/main.dart',
        args: ['--no-pub'],
        config: c,
      );
      stderr.addStream(proc.stderr);
      await stdout.addStream(proc.stdout);
    }
  });
}

Hope this help.

casimir avatar Apr 10 '24 13:04 casimir