Skip to content

Service.getInfo() does not work for test environment. #52354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
polina-c opened this issue May 11, 2023 · 5 comments
Closed

Service.getInfo() does not work for test environment. #52354

polina-c opened this issue May 11, 2023 · 5 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-service The VM Service Protocol, both the specification and its implementation

Comments

@polina-c
Copy link
Contributor

polina-c commented May 11, 2023

Steps to repro:

clone [email protected]:polina-c/spikes.git
cd spikes/connect_vm
flutter test test/widget_test.dart

See output Obtaining info... and the test never finishes.

The output is from the code:

    print('Obtaining info...');
    final info = await Service.getInfo();
    print('Obtained info.');

There is no error as well.

@polina-c
Copy link
Contributor Author

polina-c commented May 11, 2023

If I run the test by clicking 'Debug' in VSCode, I can successfully connect to the isolate with DEvTools, when test is paused, using url printed in debug console:

Screenshot 2023-05-11 at 11 24 02 AM Screenshot 2023-05-11 at 11 22 21 AM

@polina-c
Copy link
Contributor Author

Screen.Recording.2023-05-10.at.4.41.20.PM.mov

@polina-c
Copy link
Contributor Author

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-service The VM Service Protocol, both the specification and its implementation labels May 11, 2023
@bkonyi
Copy link
Contributor

bkonyi commented May 12, 2023

So I've done some digging and I'm not sure exactly what's going on here. The call to the service isolate to get the URI completes successfully and the receivePort.handler is executing completer.complete(uriString). However, the completer's future isn't completing so we hang:

static Future<ServiceProtocolInfo> getInfo() async {
  // Port to receive response from service isolate.
  final RawReceivePort receivePort =
      new RawReceivePort(null, 'Service.getInfo');
  final Completer<String?> completer = new Completer<String?>();
  receivePort.handler = (String? uriString) {
    // This callback executes
    completer.complete(uriString);
  };
  // Request the information from the service isolate.
  _getServerInfo(receivePort.sendPort);
  // Await the response from the service isolate.

  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  // **This future never completes**
  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  String? uriString = await completer.future;

  Uri? uri = uriString == null ? null : Uri.parse(uriString);
  // Close the port.
  receivePort.close();
  return new ServiceProtocolInfo(uri);
}

I wonder the event loop in flutter_tester is configured differently or does some weird stuff with futures. @christopherfujino, would you know anything about this or know who might?

@bkonyi
Copy link
Contributor

bkonyi commented May 12, 2023

@mraleph correctly identified this as an issue related to the use of FakeAsync in flutter_tester. The fix is to wrap the call to Service.getInfo() in tester.runAsync.

@bkonyi bkonyi closed this as completed May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-service The VM Service Protocol, both the specification and its implementation
Projects
None yet
Development

No branches or pull requests

3 participants