test: fix up tests after internal api change

This commit is contained in:
Ben Noordhuis 2013-07-19 23:33:06 +02:00
parent ca9eb718fb
commit e1fe8d4ec0
7 changed files with 26 additions and 67 deletions

View File

@ -36,7 +36,7 @@ if (process.argv[2] === 'child') {
sockets.push(socket);
socket.on('end', function() {
if (!this.closingOnPurpose)
throw new Error('[c] closing by accident! ' + process._errno);
throw new Error('[c] closing by accident!');
});
}

View File

@ -1,50 +0,0 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var common = require('../common');
var assert = require('assert');
if (process.argv[2] === 'child') {
process.exit(0);
} else {
var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [process.argv[1], 'child']);
var error = {};
child.on('exit', function() {
child._handle = {
kill: function() {
process._errno = 42;
return -1;
}
};
child.once('error', function(err) {
error = err;
});
child.kill();
});
process.on('exit', function() {
// we shouldn't reset errno since it accturlly isn't set
// because of the fake .kill method
assert.equal(error.syscall, 'kill');
});
}

View File

@ -44,7 +44,7 @@ p.onexit = function(exitCode, signal) {
processExited = true;
};
pipe.onread = function(b, off, len) {
pipe.onread = function(err, b, off, len) {
assert.ok(processExited);
if (b) {
gotPipeData = true;

View File

@ -23,6 +23,9 @@
var common = require('../common.js');
var assert = require('assert');
var util = require('util');
var errnoException = util._errnoException;
function parent() {
var spawn = require('child_process').spawn;
@ -62,11 +65,12 @@ function child0() {
}
W.prototype._write = function(chunk, encoding, cb) {
var req = handle.writeUtf8String(chunk.toString() + '\n');
var req = { oncomplete: afterWrite };
var err = handle.writeUtf8String(req, chunk.toString() + '\n');
if (err) throw errnoException(err, 'write');
// here's the problem.
// it needs to tell the Writable machinery that it's ok to write
// more, but that the current buffer length is handle.writeQueueSize
req.oncomplete = afterWrite
if (req.writeQueueSize === 0)
req.cb = cb;
else

View File

@ -26,14 +26,20 @@ var TCP = process.binding('tcp_wrap').TCP;
function makeConnection() {
var client = new TCP();
var req = client.connect('127.0.0.1', common.PORT);
var req = {};
var err = client.connect(req, '127.0.0.1', common.PORT);
assert.equal(err, 0);
req.oncomplete = function(status, client_, req_) {
assert.equal(0, status);
assert.equal(client, client_);
assert.equal(req, req_);
console.log('connected');
var shutdownReq = client.shutdown();
var shutdownReq = {};
var err = client.shutdown(shutdownReq);
assert.equal(err, 0);
shutdownReq.oncomplete = function(status, client_, req_) {
console.log('shutdown complete');
assert.equal(0, status);

View File

@ -36,7 +36,7 @@ var slice, sliceCount = 0, eofCount = 0;
var writeCount = 0;
var recvCount = 0;
server.onconnection = function(client) {
server.onconnection = function(err, client) {
assert.equal(0, client.writeQueueSize);
console.log('got connection');
@ -49,13 +49,15 @@ server.onconnection = function(client) {
client.readStart();
client.pendingWrites = [];
client.onread = function(buffer) {
client.onread = function(err, buffer) {
if (buffer) {
assert.ok(buffer.length > 0);
assert.equal(0, client.writeQueueSize);
var req = client.writeBuffer(buffer);
var req = {};
var err = client.writeBuffer(req, buffer);
assert.equal(err, 0);
client.pendingWrites.push(req);
console.log('client.writeQueueSize: ' + client.writeQueueSize);
@ -112,5 +114,3 @@ process.on('exit', function() {
assert.equal(1, writeCount);
assert.equal(1, recvCount);
});

View File

@ -23,17 +23,16 @@ var common = require('../common');
var assert = require('assert');
var TCP = process.binding('tcp_wrap').TCP;
var uv = process.binding('uv');
var handle = new TCP();
// Should be able to bind to the common.PORT
var r = handle.bind('0.0.0.0', common.PORT);
assert.equal(0, r);
var err = handle.bind('0.0.0.0', common.PORT);
assert.equal(err, 0);
// Should not be able to bind to the same port again
var r = handle.bind('0.0.0.0', common.PORT);
assert.equal(-1, r);
console.log(process._errno);
assert.equal(process._errno, 'EINVAL');
err = handle.bind('0.0.0.0', common.PORT);
assert.equal(err, uv.UV_EINVAL);
handle.close();