Skip to content

Commit

Permalink
Release v0.0.34
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Oct 22, 2010
1 parent bad98ff commit e11bb2d
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 5 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
2010.10.22 v0.0.34

* Added test for unix socket server.
* Corrected unix socket server argument shifting.
* Tested setuid inside test-sudo Makefile target.

2010.10.20 v0.0.32

* JSLint output is cleaner now
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -4,9 +4,12 @@ build:
node-waf configure build

test: build
node tools/test.js test_zero_workers test_one_worker test_if_i_can_reach_many_workers test_app_reload test_working_dir test_master_socket_is_protected test_leaks test_worker_dies_after_master_sudden_death
node tools/test.js test_zero_workers test_one_worker test_if_i_can_reach_many_workers test_app_reload test_working_dir test_master_socket_is_protected test_leaks test_worker_dies_after_master_sudden_death test_unix_socket

test-sudo:
sudo NODE_PATH=${NODE_PATH} PATH=${PATH} node tools/test.js test_setuid

test-fail:
node tools/test.js test_should_fail

.PHONY: all test build
.PHONY: all test build test-sudo
4 changes: 2 additions & 2 deletions lib/fugue.js
Expand Up @@ -105,7 +105,7 @@ exports.start = function(server, port, host, worker_count, options) {
var unix_socket_path = null;
if (!isPort(port)) {
// shift arguments
in_options = worker_count;
options = worker_count;
worker_count = host;
unix_socket_path = port;
}
Expand All @@ -129,7 +129,7 @@ exports.start = function(server, port, host, worker_count, options) {
})(default_options, options);
}
options = default_options;

worker_kill_timeout = options.worker_kill_timeout;

var path = require('path');
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ "name" : "fugue"
, "description" : "Unicorn for node"
, "version" : "0.0.33"
, "version" : "0.0.34"
, "homepage" : "http://www.metaduck.com/fugue"
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com> (http://www.metaduck.com)"
, "contributors" :
Expand Down
40 changes: 40 additions & 0 deletions test/test_setuid.js
@@ -0,0 +1,40 @@
//Testing to see if I can get data from 1 worker...

var path = require('path'),
net = require('net'),
assert = require('assert');
var fugue = require(path.join(__dirname, '..', 'lib', 'fugue.js'));

var expected_data = 'here is some data';
var server = net.createServer(function(conn) {
conn.end(process.getuid().toString());
});

var port = 4001;
var uid = 501;

var expected_working_path = path.join(__dirname, '..', 'examples');

exports.setup = function() {
fugue.start(server, port, null, 1, {verbose: false, uid: uid} );
}

exports.run = function(next) {

var client = net.createConnection(port);

var got_some_data = false;
client.on('data', function(uid) {
assert.equal(uid.toString(), uid);
next();
});

setTimeout(function() {
assert.ok(got_some_data, "Couldn't get data from server");
if(next) next();
}, 3000);
}

exports.teardown = function() {
fugue.stop();
}
74 changes: 74 additions & 0 deletions test/test_unix_socket.js
@@ -0,0 +1,74 @@
// Testing to see if I can reach many workers
// Setup server, spawn x workers, and then try to connect to each
// Each worker stops watcher after first connection
// Since connections might be queued on the worker before he closes the watcher, we try to connect x times x 100 (safety factor)

var path = require('path'),
net = require('net'),
assert = require('assert');
var fugue = require(path.join(__dirname, '..', 'lib', 'fugue.js'));

var expected_data = 'here is some data';
server = net.createServer(function(conn) {
if (!fugue.isMaster()) {
//console.log('worker '+fugue.workerId()+' got connection');
conn.write(fugue.workerId().toString());
conn.flush();
conn.end();
process.nextTick(function() {
server.watcher.stop();
});
}
});

var socket_path = '/tmp/fugue_test_socket_path.sock';
var worker_count = 4;

exports.run = function(next) {

var worker_marks = {};

var all_workers_contacted = function() {
for(var workerIdx = 1; workerIdx <= worker_count; workerIdx ++) {
if (!worker_marks[workerIdx]) return false;
}
return true;
}


var timeout = setTimeout(function() {
// test that we have visited all workers
assert.ok(all_workers_contacted, 'not all workers responded');
}, 4000);

fugue.start(server, socket_path, worker_count, {verbose: false, started : function() {

var workers_tried = 0;
var safety_factor = 100;
var max_tries = worker_count * safety_factor;
var try_next_worker = function() {
workers_tried ++;
workerIdx = workers_tried;
var client = net.createConnection(socket_path);

var got_some_data = false;
client.on('data', function(workerId) {
worker_marks[workerId] = true;
client.end();
if (all_workers_contacted()) {
clearTimeout(timeout);
next();
} else
if (workers_tried < max_tries) try_next_worker();
});

};
try_next_worker();

}} );

}

exports.teardown = function() {
fugue.stop();
}

0 comments on commit e11bb2d

Please sign in to comment.