Skip to content

Integration test runs twice on web platform #102250

Closed

Description

Steps to Reproduce

  1. Execute flutter drive --driver=test_driver/integration_test.dart --target=integration_test/example_test.dart -d chrome on the code sample
  2. Observe that the test fails as 2 documents have been inserted to Firestore
  3. If ran on other platform (iOS) the same behavior is not observed

Expected results:
When a single test is ran that inserts a single document a single document should be inserted

00:00 +0: (setUpAll)
00:00 +1: Single document created
Pre-existing documents: 0
00:01 +2: (tearDownAll)
00:01 +3: All tests passed!

Actual results:
When a single test is ran two documents are inserted, I think that the test is running twice

00:00 +0: (setUpAll)
00:00 +1: Single document created
Pre-existing documents: 0
00:01 +2: (tearDownAll)
00:01 +3: All tests passed!
Failure Details:
Failure in method: Single document created
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following TestFailure was thrown running a test:
Expected: <1>
  Actual: <2>
Code sample

Full repository

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  final now = DateTime.now();
  const String collectionName = 'examples';
  String currentMinute = DateFormat.yMd().add_jm().format(now);

  documentsInsertedThisMinute() async {
    var collection = FirebaseFirestore.instance.collection(collectionName);
    var snapshots =
        await collection.where('foobar', isEqualTo: currentMinute).get();
    return snapshots.size;
  }

  setUpAll(() async {
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
  });

  testWidgets(
    'Single document created',
    (WidgetTester tester) async {
      int preExistingDocuments = await documentsInsertedThisMinute();
      print('Pre-existing documents: $preExistingDocuments');

      await tester.pumpWidget(const MyApp());

      await FirebaseFirestore.instance
          .collection(collectionName)
          .doc()
          .set({'foobar': currentMinute});

      int documentsAfterSingleInsert = await documentsInsertedThisMinute();
      expect(documentsAfterSingleInsert, 1);
    },
  );
}
Logs

Gist of flutter drive --verbose

Analyzing integration_tests_duplicated...                               

   info • Avoid `print` calls in production code • integration_test/example_test.dart:32:7 • avoid_print

1 issue found. (ran in 2.2s)
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.2.1 21D62 darwin-arm, locale en-US)
    • Flutter version 2.10.4 at /Users/garrett/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c860cba910 (4 weeks ago), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/garrett/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] VS Code (version 1.66.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.38.1

[✓] Connected device (3 available)
    • Garrett’s iPad (mobile) • 00000000-0000000000000000 • ios            • iOS 15.3.1 19D52
    • macOS (desktop)         • macos                     • darwin-arm64   • macOS 12.2.1 21D62 darwin-arm
    • Chrome (web)            • chrome                    • web-javascript • Google Chrome 100.0.4896.127

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

DuplicatedDocuments

Activity

  1. darshankawar commented on Apr 21, 2022

    @darshankawar
    Member

    @garrettApproachableGeek
    Thanks for the detailed report. I think this is the case of two chrome instances being launched in the background and hence you might be seeing the behavior.

    For example, when running with -d chrome flag, one chrome instance is opened and notice that it is not labelled with chrome is controlled by automated test software.
    Also, if you run with -d chrome \ --no-headless then the chrome instance will show chrome is controlled by automated test software.

    In both above cases, the chrome instances are overlapped with each other and if you try to drag the front chrome instance away, you might see another instance.

    Can you confirm above behavior ?

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 21, 2022
  3. garrettApproachableGeek commented on Apr 21, 2022

    @garrettApproachableGeek
    Author

    When running with --no-headless I do see that there are two chrome instances and one of them says chrome is controlled by automated test software

    However when running without the --no-headless flag I only see one chrome instance, but I assume there is a headless instance running that is not visible?

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Apr 21, 2022
  5. darshankawar commented on Apr 22, 2022

    @darshankawar
    Member

    Yes and that leads me to this open issue #67090, so I suggest you to follow-up in it for further updates.
    Closing this as a duplicate, since root-cause is same as mentioned in linked issue.

  6. added
    r: duplicateIssue is closed as a duplicate of an existing issue
    and removed
    in triagePresently being triaged by the triage team
    on Apr 22, 2022
  7. github-actions commented on May 6, 2022

    @github-actions

    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 flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions