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

Commit

Permalink
testing: testing
Browse files Browse the repository at this point in the history
xyz
  • Loading branch information
orangemocha committed Feb 26, 2014
1 parent b5f9779 commit e16f739
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 40 deletions.
1 change: 1 addition & 0 deletions deps/uv/src/win/pipe.c
Expand Up @@ -1174,6 +1174,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
NULL);

if (!result) {
err = GetLastError();
return err;
} else {
/* Request completed immediately. */
Expand Down
7 changes: 6 additions & 1 deletion lib/net.js
Expand Up @@ -146,7 +146,12 @@ function Socket(options) {
this._handle = options.handle; // private
} else if (!util.isUndefined(options.fd)) {
this._handle = createHandle(options.fd);
this._handle.open(options.fd);
if ((options.fd == 1 || options.fd == 2) && process.platform === 'win32') {
// Open stdout and stderr in blocking mode on Windows
this._handle.open(options.fd, true);
} else {
this._handle.open(options.fd);
}
this.readable = options.readable !== false;
this.writable = options.writable !== false;
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/pipe_wrap.cc
Expand Up @@ -267,6 +267,10 @@ void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {

if (err != 0)
ThrowException(UVException(err, "uv_pipe_open"));

if (args.Length() > 1 && args[1]->IsTrue()) {
uv_stream_set_blocking((uv_stream_t*)&wrap->handle_, 1);
}
}


Expand Down
69 changes: 69 additions & 0 deletions test/simple/test-child-process-stdout-flush-exit.js
@@ -0,0 +1,69 @@
// 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');
var path = require('path');

// if child process output to console and exit
if (process.argv[2] === 'child') {
console.log('hello');
for (var i = 0; i < 200; i++) {
console.log('filler');
}
console.log('goodbye');
process.exit(0);
} else {
// parent process
var spawn = require('child_process').spawn;

// spawn self as child
var child = spawn(process.argv[0], [process.argv[1], 'child']);

var gotHello = false;
var gotBye = false;

child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
console.log('parent stderr: ' + data);
assert.ok(false);
});

// check if we receive both 'hello' at start and 'goodbye' at end
child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
if (data.slice(0, 6) == 'hello\n') {
gotHello = true;
} else if (data.slice(data.length - 8) == 'goodbye\n') {
gotBye = true;
} else {
gotBye = false;
}
});

child.on('close', function (data) {
assert(gotHello);
assert(gotBye);
});
}
48 changes: 9 additions & 39 deletions test/simple/test-stream2-stderr-sync.js
Expand Up @@ -32,7 +32,7 @@ function parent() {
var assert = require('assert');
var i = 0;
children.forEach(function(_, c) {
var child = spawn(process.execPath, [__filename, '' + c]);
var child = spawn(process.execPath, [__filename, '' + c], {stdio:[null,'inherit','pipe']});
var err = '';

child.stderr.on('data', function(c) {
Expand All @@ -49,43 +49,10 @@ function parent() {
}

function child0() {
// Just a very simple wrapper around TTY(2)
// Essentially the same as stderr, but without all the net stuff.
var Writable = require('stream').Writable;
var util = require('util');

// a lowlevel stderr writer
var TTY = process.binding('tty_wrap').TTY;
var handle = new TTY(2, false);

util.inherits(W, Writable);

function W(opts) {
Writable.call(this, opts);
}

W.prototype._write = function(chunk, encoding, cb) {
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
if (req.writeQueueSize === 0)
req.cb = cb;
else
cb();
}
function afterWrite(status, handle, req) {
if (req.cb)
req.cb();
}

var w = new W
w.write('child 0');
w.write('foo');
w.write('bar');
w.write('baz');
console.error('child 0');
console.error('foo');
console.error('bar');
console.error('baz');
}

// using console.error
Expand All @@ -107,7 +74,10 @@ function child2() {
// using a net socket
function child3() {
var net = require('net');
var socket = new net.Socket({ fd: 2 });
var socket = new net.Socket({
fd: 2,
readable: false,
writable: true});
socket.write('child 3\n');
socket.write('foo\n');
socket.write('bar\n');
Expand Down

0 comments on commit e16f739

Please sign in to comment.