Browse Source

test: fix async-listener-run-error-once

Rely on defined order of operations by closing the server and
destorying the client socket, instead of when setImmediate fires
v0.11.12-release
Trevor Norris 11 years ago
committed by Timothy J Fontaine
parent
commit
846f304fa8
  1. 11
      test/simple/test-asynclistener-run-error-once.js

11
test/simple/test-asynclistener-run-error-once.js

@ -24,11 +24,13 @@ var assert = require('assert');
var net = require('net'); var net = require('net');
var tracing = require('tracing'); var tracing = require('tracing');
var errMsg = 'net - error: server connection';
var cntr = 0; var cntr = 0;
var al = tracing.addAsyncListener({ var al = tracing.addAsyncListener({
error: function(stor, er) { error: function(stor, er) {
cntr++; cntr++;
process._rawDebug('Handling error: ' + er.message); process._rawDebug('Handling error: ' + er.message);
assert.equal(errMsg, er.message);
return true; return true;
} }
}); });
@ -36,21 +38,22 @@ var al = tracing.addAsyncListener({
process.on('exit', function(status) { process.on('exit', function(status) {
tracing.removeAsyncListener(al); tracing.removeAsyncListener(al);
console.log('exit status:', status);
assert.equal(status, 0); assert.equal(status, 0);
console.log('cntr:', cntr);
assert.equal(cntr, 1); assert.equal(cntr, 1);
console.log('ok'); console.log('ok');
}); });
var server = net.createServer(function(c) { var server = net.createServer(function(c) {
throw new Error('net - error: server connection'); this.close();
throw new Error(errMsg);
}); });
server.listen(common.PORT, function() { server.listen(common.PORT, function() {
net.connect(common.PORT, function() { net.connect(common.PORT, function() {
setImmediate(function() { this.destroy();
process.exit();
});
}); });
}); });

Loading…
Cancel
Save