Browse Source

test updates

v0.9.4-release
isaacs 12 years ago
parent
commit
b4df1e62de
  1. 3
      test/simple/test-child-process-ipc.js
  2. 21
      test/simple/test-http-header-response-splitting.js
  3. 15
      test/simple/test-tls-pause.js

3
test/simple/test-child-process-ipc.js

@ -42,10 +42,13 @@ child.stdout.setEncoding('utf8');
child.stdout.on('data', function(data) { child.stdout.on('data', function(data) {
console.log('child said: ' + JSON.stringify(data)); console.log('child said: ' + JSON.stringify(data));
if (!gotHelloWorld) { if (!gotHelloWorld) {
console.error('testing for hello world');
assert.equal('hello world\r\n', data); assert.equal('hello world\r\n', data);
gotHelloWorld = true; gotHelloWorld = true;
console.error('writing echo me');
child.stdin.write('echo me\r\n'); child.stdin.write('echo me\r\n');
} else { } else {
console.error('testing for echo me');
assert.equal('echo me\r\n', data); assert.equal('echo me\r\n', data);
gotEcho = true; gotEcho = true;
child.stdin.end(); child.stdin.end();

21
test/simple/test-http-header-response-splitting.js

@ -27,6 +27,7 @@ var testIndex = 0,
responses = 0; responses = 0;
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
console.error('request', testIndex);
switch (testIndex++) { switch (testIndex++) {
case 0: case 0:
res.writeHead(200, { test: 'foo \r\ninvalid: bar' }); res.writeHead(200, { test: 'foo \r\ninvalid: bar' });
@ -41,6 +42,7 @@ var server = http.createServer(function(req, res) {
res.writeHead(200, { test: 'foo \n\n\ninvalid: bar' }); res.writeHead(200, { test: 'foo \n\n\ninvalid: bar' });
break; break;
case 4: case 4:
console.error('send request, then close');
res.writeHead(200, { test: 'foo \r\n \r\n \r\ninvalid: bar' }); res.writeHead(200, { test: 'foo \r\n \r\n \r\ninvalid: bar' });
server.close(); server.close();
break; break;
@ -49,15 +51,16 @@ var server = http.createServer(function(req, res) {
} }
res.end('Hi mars!'); res.end('Hi mars!');
}); });
server.listen(common.PORT); server.listen(common.PORT, function() {
for (var i = 0; i < 5; i++) {
for (var i = 0; i < 5; i++) { var req = http.get({ port: common.PORT, path: '/' }, function(res) {
var req = http.get({ port: common.PORT, path: '/' }, function(res) { assert.strictEqual(res.headers.test, 'foo invalid: bar');
assert.strictEqual(res.headers.test, 'foo invalid: bar'); assert.strictEqual(res.headers.invalid, undefined);
assert.strictEqual(res.headers.invalid, undefined); responses++;
responses++; res.resume();
}); });
} }
});
process.on('exit', function() { process.on('exit', function() {
assert.strictEqual(responses, 5); assert.strictEqual(responses, 5);

15
test/simple/test-tls-pause.js

@ -41,6 +41,9 @@ var received = 0;
var server = tls.Server(options, function(socket) { var server = tls.Server(options, function(socket) {
socket.pipe(socket); socket.pipe(socket);
socket.on('data', function(c) {
console.error('data', c.length);
});
}); });
server.listen(common.PORT, function() { server.listen(common.PORT, function() {
@ -49,11 +52,16 @@ server.listen(common.PORT, function() {
port: common.PORT, port: common.PORT,
rejectUnauthorized: false rejectUnauthorized: false
}, function() { }, function() {
console.error('connected');
client.pause(); client.pause();
common.debug('paused'); common.debug('paused');
send(); send();
function send() { function send() {
if (client.write(new Buffer(bufSize))) { console.error('sending');
var ret = client.write(new Buffer(bufSize));
console.error('write => %j', ret);
if (false !== ret) {
console.error('write again');
sent += bufSize; sent += bufSize;
assert.ok(sent < 100 * 1024 * 1024); // max 100MB assert.ok(sent < 100 * 1024 * 1024); // max 100MB
return process.nextTick(send); return process.nextTick(send);
@ -62,12 +70,15 @@ server.listen(common.PORT, function() {
common.debug('sent: ' + sent); common.debug('sent: ' + sent);
resumed = true; resumed = true;
client.resume(); client.resume();
common.debug('resumed'); console.error('resumed', client);
} }
}); });
client.on('data', function(data) { client.on('data', function(data) {
console.error('data');
assert.ok(resumed); assert.ok(resumed);
received += data.length; received += data.length;
console.error('received', received);
console.error('sent', sent);
if (received >= sent) { if (received >= sent) {
common.debug('received: ' + received); common.debug('received: ' + received);
client.end(); client.end();

Loading…
Cancel
Save