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...
A queue is a FIFO (First In First Out) data structure where the element that is added first will be deleted first. It takes the data from one end and removes it from the other end. Queues are useful when you want to build a first-in, first-out collection of data. It is the special case of list implementation of data in Dart.
The event queue mechanism allows you to serialize incoming events for your task. You can use it to get information about hardware interrupts, callout expirations, and messages from other tasks. The benefit of using events for inter-task communication is that it can reduce the number of resources that need to be shared and locked.
In Dart, though, each thread is in its own isolate with its own memory, and the thread just processes events (more on that in a minute). Many Dart apps run all their code in a single isolate, but you can have more than one if you need it.
Create a task that generates an event at periodic intervals and adds, using the os_eventq_put () function, the event to the Mynewt default event queue:
The observatory now (Dart VM version: 1.11.0-edge.131775) allows to investigate the message queue in the debugger view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With