Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
test: replace .addListener() calls with .on()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Oct 14, 2011
1 parent 3108a9e commit 018e110
Show file tree
Hide file tree
Showing 126 changed files with 421 additions and 421 deletions.
2 changes: 1 addition & 1 deletion test/disabled/test-cat.js
Expand Up @@ -70,7 +70,7 @@ promise.addErrback(function() {
errors += 1;
});

process.addListener('exit', function() {
process.on('exit', function() {
assert.equal(2, successes);
assert.equal(0, errors);
});
12 changes: 6 additions & 6 deletions test/disabled/test-child-process-custom-fds.js
Expand Up @@ -50,7 +50,7 @@ function test1(next) {
assert.equal(child.stdout, null);
assert.notEqual(child.stderr, null);

child.addListener('exit', function(err) {
child.on('exit', function(err) {
if (err) throw err;
fs.close(fd, function(error) {
if (error) throw error;
Expand All @@ -77,10 +77,10 @@ function test2(next) {

assert.equal(child.stdin, null);
var actualData = '';
child.stdout.addListener('data', function(data) {
child.stdout.on('data', function(data) {
actualData += data.toString();
});
child.addListener('exit', function(code) {
child.on('exit', function(code) {
if (err) throw err;
assert.equal(actualData, 'hella warld\n');
console.log(' File was filtered successfully');
Expand All @@ -98,16 +98,16 @@ function test3(next) {
var filter = spawn(process.argv[0], [fixtPath('stdio-filter.js'), 'o', 'a']);
var echo = spawn('/bin/echo', [expected], {customFds: [-1, filter.fds[0]]});
var actualData = '';
filter.stdout.addListener('data', function(data) {
filter.stdout.on('data', function(data) {
console.log(' Got data --> ' + data);
actualData += data;
});
filter.addListener('exit', function(code) {
filter.on('exit', function(code) {
if (code) throw 'Return code was ' + code;
assert.equal(actualData, 'hella warld\n');
console.log(' Talked to another process successfully');
});
echo.addListener('exit', function(code) {
echo.on('exit', function(code) {
if (code) throw 'Return code was ' + code;
filter.stdin.end();
fs.unlinkSync(helloPath);
Expand Down
4 changes: 2 additions & 2 deletions test/disabled/test-fs-sendfile.js
Expand Up @@ -31,7 +31,7 @@ var x = path.join(common.fixturesDir, 'x.txt');
var expected = 'xyz';

var server = net.createServer(function(socket) {
socket.addListener('receive', function(data) {
socket.on('receive', function(data) {
found = data;
client.close();
socket.close();
Expand All @@ -42,7 +42,7 @@ var server = net.createServer(function(socket) {
server.listen(common.PORT);

var client = net.createConnection(common.PORT);
client.addListener('connect', function() {
client.on('connect', function() {
fs.open(x, 'r').addCallback(function(fd) {
fs.sendfile(client.fd, fd, 0, expected.length)
.addCallback(function(size) {
Expand Down
10 changes: 5 additions & 5 deletions test/disabled/test-http-big-proxy-responses.js
Expand Up @@ -68,14 +68,14 @@ var proxy = http.createServer(function(req, res) {

var count = 0;

proxy_res.addListener('data', function(d) {
proxy_res.on('data', function(d) {
if (count++ % 1000 == 0) common.print('.');
res.write(d);
sent += d.length;
assert.ok(sent <= (len * chunk.length));
});

proxy_res.addListener('end', function() {
proxy_res.on('end', function() {
res.end();
});

Expand All @@ -102,12 +102,12 @@ function call_chargen(list) {
headers: {'x-len': len}
}, function(res) {

res.addListener('data', function(d) {
res.on('data', function(d) {
recved += d.length;
assert.ok(recved <= (len * chunk.length));
});

res.addListener('end', function() {
res.on('end', function() {
assert.ok(recved <= (len * chunk.length));
common.debug('end for ' + len + ' chunks.');
call_chargen(list);
Expand All @@ -130,6 +130,6 @@ function ready() {
call_chargen([100, 1000, 10000, 100000, 1000000]);
}

process.addListener('exit', function() {
process.on('exit', function() {
assert.ok(done);
});
6 changes: 3 additions & 3 deletions test/disabled/test-http-head-request.js
Expand Up @@ -44,17 +44,17 @@ server.listen(common.PORT);

var gotEnd = false;

server.addListener('listening', function() {
server.on('listening', function() {
var request = http.request({
port: common.PORT,
method: 'HEAD',
path: '/'
}, function(response) {
console.log('got response');
response.addListener('data', function() {
response.on('data', function() {
process.exit(2);
});
response.addListener('end', function() {
response.on('end', function() {
process.exit(0);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/disabled/test-http-stress.js
Expand Up @@ -40,7 +40,7 @@ server.listen(common.PORT);
var requests_ok = 0;
var requests_complete = 0;

server.addListener('listening', function() {
server.on('listening', function() {
for (var i = 0; i < request_count; i++) {
http.cat('http://localhost:' + common.PORT + '/', 'utf8',
function(err, content) {
Expand All @@ -60,7 +60,7 @@ server.addListener('listening', function() {
}
});

process.addListener('exit', function() {
process.on('exit', function() {
assert.equal(request_count, requests_complete);
assert.equal(request_count, requests_ok);
});
14 changes: 7 additions & 7 deletions test/disabled/test-http-tls.js
Expand Up @@ -111,16 +111,16 @@ var https_server = http.createServer(function(req, res) {
https_server.setSecure(credentials);
https_server.listen(common.PORT);

https_server.addListener('listening', function() {
https_server.on('listening', function() {
var c = net.createConnection(common.PORT);

c.setEncoding('utf8');

c.addListener('connect', function() {
c.on('connect', function() {
c.setSecure(credentials);
});

c.addListener('secure', function() {
c.on('secure', function() {
var verified = c.verifyPeer();
var peerDN = JSON.stringify(c.getPeerCertificate());
assert.equal(verified, true);
Expand All @@ -137,7 +137,7 @@ https_server.addListener('listening', function() {
requests_sent += 1;
});

c.addListener('data', function(chunk) {
c.on('data', function(chunk) {
server_response += chunk;

if (requests_sent == 1) {
Expand All @@ -155,16 +155,16 @@ https_server.addListener('listening', function() {

});

c.addListener('end', function() {
c.on('end', function() {
client_got_eof = true;
});

c.addListener('close', function() {
c.on('close', function() {
assert.equal(c.readyState, 'closed');
});
});

process.addListener('exit', function() {
process.on('exit', function() {
assert.equal(4, request_number);
assert.equal(4, requests_sent);

Expand Down
2 changes: 1 addition & 1 deletion test/disabled/test-idle-watcher.js
Expand Up @@ -34,6 +34,6 @@ idle.callback = function() {
idle.setPriority(process.EVMAXPRI);
idle.start();

process.addListener('exit', function() {
process.on('exit', function() {
assert.ok(complete);
});
12 changes: 6 additions & 6 deletions test/disabled/test-net-fd-passing.js
Expand Up @@ -41,21 +41,21 @@ function fdPassingTest(path, port) {
var initializeSender = function() {
var fdHighway = new net.Socket();

fdHighway.addListener('connect', function() {
fdHighway.on('connect', function() {
var sender = net.createServer(function(socket) {
fdHighway.sendFD(socket);
socket.flush();
socket.forceClose(); // want to close() the fd, not shutdown()
});

sender.addListener('listening', function() {
sender.on('listening', function() {
var client = net.createConnection(port);

client.addListener('connect', function() {
client.on('connect', function() {
client.write(message);
});

client.addListener('data', function(data) {
client.on('data', function(data) {
assert.equal(expectedData[0], data);
if (expectedData.length > 1) {
expectedData.shift();
Expand All @@ -78,7 +78,7 @@ function fdPassingTest(path, port) {

};

receiver.addListener('output', function(data) {
receiver.on('output', function(data) {
var initialized = false;
if ((! initialized) && (data == 'ready')) {
initializeSender();
Expand All @@ -89,6 +89,6 @@ function fdPassingTest(path, port) {

fdPassingTest('/tmp/passing-socket-test', 31075);

process.addListener('exit', function() {
process.on('exit', function() {
assert.equal(1, tests_run);
});
14 changes: 7 additions & 7 deletions test/disabled/test-net-tls-pummel.js
Expand Up @@ -47,7 +47,7 @@ function tlsTest(port, host, caPem, keyPem, certPem) {
socket.setNoDelay();
socket.timeout = 0;

socket.addListener('data', function(data) {
socket.on('data', function(data) {
var verified = socket.verifyPeer();
var peerDN = socket.getPeerCertificate('DNstring');
assert.equal(verified, 1);
Expand All @@ -62,12 +62,12 @@ function tlsTest(port, host, caPem, keyPem, certPem) {
}
});

socket.addListener('end', function() {
socket.on('end', function() {
assert.equal('writeOnly', socket.readyState);
socket.end();
});

socket.addListener('close', function(had_error) {
socket.on('close', function(had_error) {
assert.equal(false, had_error);
assert.equal('closed', socket.readyState);
socket.server.close();
Expand All @@ -82,7 +82,7 @@ function tlsTest(port, host, caPem, keyPem, certPem) {
client.setEncoding('utf8');
client.setSecure('X509_PEM', caPem, 0, keyPem, caPem);

client.addListener('connect', function() {
client.on('connect', function() {
assert.equal('open', client.readyState);
var verified = client.verifyPeer();
var peerDN = client.getPeerCertificate('DNstring');
Expand All @@ -93,7 +93,7 @@ function tlsTest(port, host, caPem, keyPem, certPem) {
client.write('PING');
});

client.addListener('data', function(data) {
client.on('data', function(data) {
assert.equal('PONG', data);
count += 1;

Expand All @@ -115,7 +115,7 @@ function tlsTest(port, host, caPem, keyPem, certPem) {
}
});

client.addListener('close', function() {
client.on('close', function() {
assert.equal(N + 1, count);
assert.equal(true, sent_final_ping);
tests_run += 1;
Expand All @@ -141,7 +141,7 @@ if (have_tls) {
tlsTest(common.PORT, 'localhost', caPem, keyPem, certPem);
tlsTest(common.PORT + 1, null, caPem, keyPem, certPem);

process.addListener('exit', function() {
process.on('exit', function() {
assert.equal(2, tests_run);
});
} else {
Expand Down
18 changes: 9 additions & 9 deletions test/disabled/test-net-tls.js
Expand Up @@ -63,7 +63,7 @@ var secureServer = net.createServer(function(connection) {
connection.setSecure(credentials);
connection.setEncoding('UTF8');

connection.addListener('secure', function() {
connection.on('secure', function() {
gotSecureServer = true;
var verified = connection.verifyPeer();
var peerDN = JSON.stringify(connection.getPeerCertificate());
Expand All @@ -80,28 +80,28 @@ var secureServer = net.createServer(function(connection) {

});

connection.addListener('data', function(chunk) {
connection.on('data', function(chunk) {
serverData += chunk;
connection.write(chunk);
});

connection.addListener('end', function() {
connection.on('end', function() {
assert.equal(serverData, testData);
connection.end();
self.close();
});
});
secureServer.listen(common.PORT);

secureServer.addListener('listening', function() {
secureServer.on('listening', function() {
var secureClient = net.createConnection(common.PORT);

secureClient.setEncoding('UTF8');
secureClient.addListener('connect', function() {
secureClient.on('connect', function() {
secureClient.setSecure(credentials);
});

secureClient.addListener('secure', function() {
secureClient.on('secure', function() {
gotSecureClient = true;
var verified = secureClient.verifyPeer();
var peerDN = JSON.stringify(secureClient.getPeerCertificate());
Expand All @@ -120,16 +120,16 @@ secureServer.addListener('listening', function() {
secureClient.end();
});

secureClient.addListener('data', function(chunk) {
secureClient.on('data', function(chunk) {
clientData += chunk;
});

secureClient.addListener('end', function() {
secureClient.on('end', function() {
assert.equal(clientData, testData);
});
});

process.addListener('exit', function() {
process.on('exit', function() {
assert.ok(gotSecureServer, 'Did not get secure event for server');
assert.ok(gotSecureClient, 'Did not get secure event for client');
});
4 changes: 2 additions & 2 deletions test/disabled/test-process-title.js
Expand Up @@ -40,8 +40,8 @@ function verifyProcessName(str, callback) {
var buf = '';
ps = spawn('ps');
ps.stdout.setEncoding('utf8');
ps.stdout.addListener('data', function(s) { buf += s; });
ps.addListener('exit', function(c) {
ps.stdout.on('data', function(s) { buf += s; });
ps.on('exit', function(c) {
try {
assert.equal(0, c);
assert.ok(new RegExp(process.pid + ' ', 'm').test(buf));
Expand Down
2 changes: 1 addition & 1 deletion test/disabled/test-remote-module-loading.js
Expand Up @@ -57,6 +57,6 @@ util.exec(cmd, function(err, stdout, stderr) {
server.close();
});

process.addListener('exit', function() {
process.on('exit', function() {
assert.equal(1, modulesLoaded);
});

0 comments on commit 018e110

Please sign in to comment.