Dart事件队列:如何调试事件队列? [英] Dart Event Queue: How to debug event queue?
问题描述
我正在编写一些使用 HttpServer
,一堆 Directory()的整合测试watch()
I'm writing some integration tests which utilize an HttpServer
, a bunch of Directory().watch()
'ers and possibly some other future/stream listening code.
我使用以下测试配置:
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("");
});
});
});
}
我遇到的问题是,测试运行后VM不退出。大概是因为我在事件队列中还有待处理的事件。
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.
如何调试事件队列?我想看看是什么阻止Dart VM在测试运行结束时退出。
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.
您可以在自定义TestConfiguration中看到我重载onDone()这个被调用,我停止()我的服务器( .close(force:true)
在HttpServer和循环所有的 Directory )
提供并取消订阅)。
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...
推荐答案
现在的观察站(Dart VM版本:1.11.0-edge.131775)允许在调试器视图中调查消息队列。
The observatory now (Dart VM version: 1.11.0-edge.131775) allows to investigate the message queue in the debugger view.
这篇关于Dart事件队列:如何调试事件队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!