Dart Event Queue: How to debug event queue?

只愿长相守 提交于 2019-12-12 14:55:14

问题


I'm writing some integration tests which utilize an HttpServer, a bunch of Directory().watch()'ers and possibly some other future/stream listening code.

I'm using the following test configuration:

class LaserServerTestConfiguration extends SimpleConfiguration {
  LaserServer _server;
  LaserServerTestConfiguration(this._server);
  void onDone(bool success) {
    super.onDone(success);
    _server.stop();
  }
}

And my tests look like this:

main() {
  var conf = new LaserConfiguration.fromPath('test/test_config.yaml');
  var server = new LaserServer(conf);
  unittestConfiguration = new LaserServerTestConfiguration(server);

  server.start().then((_) {

    test('test file changed event', () {
      var response = new Completer<Map>();
      response.future.then(expectAsync((e) =>
        expect(e, containsValue('test/sample/sample_test.html'))
      ));
      WebSocket.connect("ws://localhost:2014").then((ws) {
        ws.listen((msg) {
          response.complete(JSON.decode(msg));
          ws.close();
        });
        new File('test/sample/sample.dart').writeAsString("");
      });
    });

  });
}

The problem I have is that after the tests run (and pass) the Dart VM does not exit. Presumably because I still have something pending in the event queue.

How do I debug the event queue? I would like to see what is preventing the Dart VM from exiting at the end of the test run.

You can see in the custom TestConfiguration that I overload onDone(), this gets called and I stop() my server (.close(force: true) on HttpServer and loop all of my Directory().watch()'ers and cancel the subscriptions). But something is still hanging around...


回答1:


The observatory now (Dart VM version: 1.11.0-edge.131775) allows to investigate the message queue in the debugger view.



来源:https://stackoverflow.com/questions/27024868/dart-event-queue-how-to-debug-event-queue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!