juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
825 stars 478 forks source link

[Web] Mobile scanner lib blocks execution of integration tests on web #278

Open rzetzsche opened 2 years ago

rzetzsche commented 2 years ago

I discovered recently that my integration tests freeze on CI/CD. After investigation I discovered that I've updated from qr_code_scanner to mobile_scanner and after that update my integration tests stopped working. They neither success nor fail, they just freeze blocking my pipeline till timeout comes through. If I migrate back to qr_code_scanner my integration tests work again without a hick up.

The integration tests on Android run pretty normal, only the web execution will fail.

Tested with flutter 3.0.0 and 3.3.0, Windows 11 and MacOS 12.5 1 and chromedriver 105.0.5195.52.

After I messed around with the problem, I discovered that headless as well as normal web execution will fail.

I execute the tests on chrome with:

flutter drive --driver=test_driver/integration_test.dart --target=integration_test/test.dart -d chrome --browser-dimension=540,1170

or headless with:

flutter drive --driver=test_driver/integration_test.dart --target=integration_test/test.dart -d web-server --browser-dimension=540,1170

Logs

Chrome logs

Error: Assertion failed: file:///C:/Users/XXX/fvm/versions/stable/packages/flutter/lib/src/foundation/binding.dart:146:12
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49      throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3        assertFailed
packages/flutter/src/foundation/binding.dart 146:34                                                                            new
packages/flutter_test/src/binding.dart 98:54                                                                                   new
packages/flutter_test/src/binding.dart 98:54                                                                                   new
packages/flutter_test/src/binding.dart 98:54                                                                                   new
packages/flutter_test/src/binding.dart 98:54                                                                                   new
packages/flutter_test/src/binding.dart 98:54                                                                                   new
packages/flutter_test/src/binding.dart 98:54                                                                                   new
packages/flutter_test/src/binding.dart 98:54                                                                                   new
packages/flutter_test/src/binding.dart 98:54                                                                                   new
packages/flutter_test/src/binding.dart 154:3                                                                                   new
packages/flutter_test/src/binding.dart 1183:36                                                                                 new
packages/flutter_test/src/binding.dart 1008:7                                                                                  ensureInitialized
packages/flutter_test/src/_binding_web.dart 11:45                                                                              ensureInitialized
packages/flutter_test/src/binding.dart 313:20                                                                                  ensureInitialized
packages/flutter_test/src/widget_tester.dart 143:71                                                                            testWidgets
test.dart 6:3                                                                                                                  main$
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5                _async
test.dart 5:10                                                                                                                 main$
web_entrypoint.dart 24:31                                                                                                      <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14  _checkAndCall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39  dcall
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/ui/initialization.dart 77:15                                  <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1653:54                                              runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 147:18                                        handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 766:44                                        handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 795:13                                        _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 566:5                                         [_completeWithValue]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 639:7                                         callback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 40:11                                  _microtaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/schedule_microtask.dart 49:5                                   _startMicrotaskLoop
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15               <fn>

Headless logs of chromedriver

[0907/131746.058:ERROR:command_buffer_proxy_impl.cc(128)] ContextResult::kTransientFailure: Failed to send GpuControl.CreateCommandBuffer.
[0907/131748.255:INFO:CONSOLE(98)] "Installed new service worker.", source: http://localhost:52318/flutter.js (98)
[0907/131748.255:INFO:CONSOLE(68)] "Injecting <script> tag.", source: http://localhost:52318/flutter.js (68)
[0907/131749.558:INFO:CONSOLE(29633)] "Flutter Web Bootstrap: Programmatic", source: http://localhost:52318/dart_sdk.js (29633)
[0907/131749.567:INFO:CONSOLE(52110)] "registerExtension() from dart:developer is only supported in build/run/test environments where the developer event method hooks have been set by package:dwds v11.1.0 or higher.", source: http://localhost:52318/dart_sdk.js (52110)
[0907/131750.307:INFO:CONSOLE(5241)] "Uncaught (in promise) Error", source: http://localhost:52318/dart_sdk.js (5241)

Code sample

testdriver/integration_test.dart
import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
integration_test/test.dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router_test/main.dart';

void main() async {
  testWidgets('test', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      builder: (context, child) => MyHomePage(title: "TEST"),
    ));
    await tester.pumpAndSettle();
  });
}
saiful-apx commented 2 years ago

I have found that after adding mobile_scanner in pubspec, the asynchronous errors from callbacks like button onPress do not get caught in runZoneGuarded onError callback.

dallas1287 commented 1 year ago

Anybody working on this?

navaronbracke commented 6 months ago

@rzetzsche Does this still occur on mobile_scanner version 4.0.1 (or the new beta, version 5.0.0-beta.1)

It seems you are hitting an assert on the Dart side? I plan on adding integration tests to mobile_scanner itself in the future to hopefully prevent issues like this.