Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |