Skip to content

Attaching to flutter tests no longer works #2936

Closed
flutter/flutter
#70847

Description

@DanTup
  • Run flutter test --start-paused test/widget_test.dart
  • Try to attach using the following:
    {
      "name": "Dart: Attach to Test",
      "type": "dart",
      "request": "attach",
      "vmServiceUri": "${command:dart.promptForVmService}",
    },
    

It'll fail and quit. We essentially run flutter attach --machine -d macos --debug-uri http://127.0.0.1:52407/HASY0oHZsH0=/ which will fail in the same way from the terminal.

It seems to be because we're using flutter attach. I suspect either that's changed, or in the past we would use the VM directly for attaching to tests.

As a workaround, you can use cwd to prevent detecting it's a Flutter project and attaching with Dart:

  "cwd": "test",

Activity

  1. added
    in flutterRelates to running Flutter apps
    in testingRelates to test execution of Dart/Flutter tests for end users
    on Nov 5, 2020
  2. added this to the v3.17.0 milestone on Nov 5, 2020
  3. DanTup commented on Nov 18, 2020

    @DanTup
    MemberAuthor

    I think this actually became broken by DDS changes, though I'm not sure whether the old behaviour was an intended workflow or just accidentally worked.

    @jonahwilliams @bkonyi on current stable, if I start tests paused using:

    flutter test --start-paused test/widget_test.dart
    

    I can then attach to them with flutter attach:

    flutter attach -d flutter-tester --debug-uri http://127.0.0.1:54709/lAhyvyNgJpg=/ 
    

    This is (mostly) what happens if you were to run Debug: Attach to Dart Process in VS Code. We detect the project is Flutter, so we use flutter attach (at the time of attaching, we do not know if it's a test or a real Flutter app, so we have to use flutter attach since it may be an app and attaching just as a Dart app would lose some Flutter functionality).

    The same steps do not work on master. When you try to attach in the same way, you see (if running in verbose mode):

    [  +50 ms] Warning: Failed to start DDS: A DDS instance is already connected at http://127.0.0.1:54815/HfD3aZOVCDc=/.
    [        ] Fail to connect to service protocol: http://127.0.0.1:54815/HfD3aZOVCDc=/: DartDevelopmentServiceException: A DDS instance is already connected at
    http://127.0.0.1:54815/HfD3aZOVCDc=/.
    [   +3 ms] Error connecting to the service protocol: failed to connect to http://127.0.0.1:54815/HfD3aZOVCDc=/
    [  +11 ms] "flutter attach" took 498ms.
    

    Is this expected to work? It was hit by @terrylucas recently.

  4. modified the milestones: v3.17.0, On Deck on Nov 18, 2020
  5. bkonyi commented on Nov 18, 2020

    @bkonyi

    That shouldn't be a fatal error since the VM service will redirect a client to connect to an existing DDS instance if there is one. However, in the attach case we don't know if DDS is running or not so we just try to spin it up and connect. If DDS is already running, there's no issue continuing with the attach.

  6. DanTup commented on Nov 18, 2020

    @DanTup
    MemberAuthor

    That shouldn't be a fatal error

    Does that mean this is a bug somewhere? It's causing the tool to quit right now - though I'm not sure if that's because Flutter isn't handling it correctly, or something in the VM/DDS? Here's the full stack from the error:

    [  +50 ms] Warning: Failed to start DDS: A DDS instance is already connected at http://127.0.0.1:54815/HfD3aZOVCDc=/.
    [        ] Fail to connect to service protocol: http://127.0.0.1:54815/HfD3aZOVCDc=/: DartDevelopmentServiceException: A DDS instance is already connected at
    http://127.0.0.1:54815/HfD3aZOVCDc=/.
    [   +3 ms] Error connecting to the service protocol: failed to connect to http://127.0.0.1:54815/HfD3aZOVCDc=/
    [  +11 ms] "flutter attach" took 498ms.
    [   +3 ms] 
               #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
               #1      AttachCommand._attachToDevice (package:flutter_tools/src/commands/attach.dart:358:11)
               <asynchronous suspension>
               #2      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
               <asynchronous suspension>
               #3      AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
               <asynchronous suspension>
               #4      AttachCommand.runCommand (package:flutter_tools/src/commands/attach.dart:203:5)
               <asynchronous suspension>
               #5      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1120:12)
               <asynchronous suspension>
               #6      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:975:27)
               <asynchronous suspension>
               #7      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
               <asynchronous suspension>
               #8      AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
               <asynchronous suspension>
               #9      CommandRunner.runCommand (package:args/command_runner.dart:197:13)
               <asynchronous suspension>
               #10     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:264:9)
               <asynchronous suspension>
               #11     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
               <asynchronous suspension>
               #12     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
               <asynchronous suspension>
               #13     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:220:5)
               <asynchronous suspension>
               #14     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:63:9)
               <asynchronous suspension>
               #15     run.<anonymous closure> (package:flutter_tools/runner.dart:61:12)
               <asynchronous suspension>
               #16     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
               <asynchronous suspension>
               #17     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
               <asynchronous suspension>
               #18     runInContext (package:flutter_tools/src/context_runner.dart:70:10)
               <asynchronous suspension>
               #19     main (package:flutter_tools/executable.dart:90:3)
               <asynchronous suspension>
               
               
    [   +2 ms] Running shutdown hooks
    
  7. bkonyi commented on Nov 18, 2020

    @bkonyi

    Yeah, looks like it's not being handled correctly. I'll take a look.

  8. DanTup commented on Nov 18, 2020

    @DanTup
    MemberAuthor

    Thanks! (LMK if you want e to file an SDK bug for it)

  9. added and removed
    in flutterRelates to running Flutter apps
    in testingRelates to test execution of Dart/Flutter tests for end users
    on Nov 18, 2020
  10. modified the milestones: On Deck, v3.17.0 on Nov 19, 2020
  11. modified the milestones: v3.17.0, v3.18.0 on Nov 30, 2020
  12. DanTup commented on Dec 7, 2020

    @DanTup
    MemberAuthor
  13. removed this from the v3.18.0 milestone on Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions