Skip to content

Commit 284aa10

Browse files
committed
Update tests to disconnect themselves
Now that the library can disconnect itself and not keep the node process running with open handles, we can update the tests to disconnect and let the processes exit naturally, rather than forcing it with `process.exit()`.
1 parent 142ea69 commit 284aa10

9 files changed

+21
-12
lines changed

test/client-call-add.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ withService('service.js', function(err, done) {
1818
iface.Add(109, 201, function(err, result) {
1919
tap.equal(result, 310);
2020
done();
21+
bus.disconnect();
2122
});
2223
});
2324
});

test/client-call-noargs.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ withService('service.js', function(err, done) {
1818
iface.NoArgs(function(err, result) {
1919
tap.equal(result, 'result!');
2020
done();
21+
bus.disconnect();
2122
});
2223
});
2324
});

test/client-call-timeout.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ withService('service.js', function(err, done) {
1414
tap.notSame(err, null);
1515
tap.same(result, null);
1616
done();
17+
bus.disconnect();
1718
});
1819
});
1920
});

test/client-property.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ withService('service.js', function(err, done) {
2424
tap.equal(props.Author, 'Douglas Adams');
2525
tap.equal(props.URL, 'http://stem.mandice.org');
2626
done();
27+
bus.disconnect();
2728
});
2829
});
2930
});

test/client-signal.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ withService('service.js', function(err, done) {
1313
iface.on('pump', function() {
1414
tap.pass('Signal received');
1515
done();
16+
bus.disconnect();
1617
});
1718
});
1819
});

test/service-create-remove-object.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ withService('service-dynamic.js', function(err, done) {
2222
checkInterface(bus, '2', function(err, result) {
2323
tap.equal(result, false);
2424
done();
25+
bus.disconnect();
2526
});
2627
});
2728
});

test/service-dynamic.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ process.on('message', function(msg) {
3535
process.send({ type: 'remove', value: value });
3636
}
3737
}
38+
else if (msg.message === 'done') {
39+
service.disconnect();
40+
process.removeAllListeners('message');
41+
}
3842
});
3943

4044
process.send({ message: 'ready' });

test/service.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ iface1.addMethod('Add', { in: [DBus.Define(Number), DBus.Define(Number)], out: D
2121
iface1.addMethod('LongProcess', { out: DBus.Define(Number) }, function(callback) {
2222
setTimeout(function() {
2323
callback(0);
24-
}, 5000);
24+
}, 5000).unref();
2525
});
2626

2727
var author = 'Fred Chien';
@@ -57,10 +57,11 @@ iface1.addSignal('pump', {
5757
iface1.update();
5858

5959
// Emit signal per one second
60-
setInterval(function() {
60+
var interval = setInterval(function() {
6161
counter++;
6262
iface1.emit('pump', counter);
6363
}, 1000);
64+
interval.unref();
6465

6566
// Create second interface
6667
var iface2 = obj.createInterface('test.dbus.TestService.Interface2');
@@ -72,3 +73,10 @@ iface2.addMethod('Hello', { out: DBus.Define(String) }, function(callback) {
7273
iface2.update();
7374

7475
process.send({ message: 'ready' });
76+
process.on('message', function(msg) {
77+
if (msg.message === 'done') {
78+
clearInterval(interval);
79+
service.disconnect();
80+
process.removeAllListeners('message');
81+
}
82+
});

test/with-service.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function withService(name, callback) {
66
var p = child_process.fork(path.join(__dirname, name));
77

88
var done = function() {
9-
p.kill();
9+
p.send({ message: 'done' });
1010
}
1111

1212
done.process = p;
@@ -19,15 +19,6 @@ function withService(name, callback) {
1919
callback(null, done);
2020
}
2121
});
22-
23-
p.on('exit', function() {
24-
// Because there is no way to shut down a connection, the node
25-
// process keeps running after we're done with our testing. The
26-
// way we handle this, then, is that when a test is done using
27-
// the service, we kill the process that we started. And once
28-
// that process has exited, we kill the current process.
29-
process.exit();
30-
});
3122
}
3223

3324
module.exports = withService;

0 commit comments

Comments
 (0)