Skip to content
Browse files

[lib] temporary work around for nextTick never firing,

[examples] robust server.js
[test] removed a redundant assert
  • Loading branch information...
1 parent 679b6d1 commit ce14bfe9a59690b76a41539398edf2cb0ab0e513 @jamesonjlee jamesonjlee committed
Showing with 27 additions and 16 deletions.
  1. +18 −8 examples/chroot-jail/server.js
  2. +9 −7 lib/carapace.js
  3. +0 −1 test/helper/macros.js
View
26 examples/chroot-jail/server.js
@@ -1,16 +1,26 @@
var port, server;
-port = exports.port = 1337;
-server = exports.server = require('http').createServer(function (req,res) {
+// default port to listen to
+port = 1337;
+
+// Unless a specific port is request via argv
+if (process.argv.length === 4) {
+ // if we get a --port and the value passed is a number
+ if (process.argv[2] === '--port' && Number(process.argv[3])) {
+ // should set the passed value as the port
+ port = Number(process.argv[3]);
+ }
+}
+
+// start the http server
+server = require('http').createServer(function (req,res) {
console.dir('server.js got a request');
res.end(process.cwd());
});
+// export before we leave
+exports.port = port;
+exports.server = server;
-// Ultra-Naive port binding
-if (process.argv.length === 4) {
- port = process.argv[3];
-}
-
-// listen
+// and start the server
server.listen(port);
View
16 lib/carapace.js
@@ -161,12 +161,6 @@ carapace.run = function (script, argv, override, callback) {
}
//
- // Dereference `libev` so that this connection
- // does not keep the event loop alive
- //
- evref.unref();
-
- //
// Rewrite `process.argv` so that `Module.runMain()`
// will transparently locate and run the target script
// and it will be completely unaware of the carapace.
@@ -202,6 +196,14 @@ carapace.run = function (script, argv, override, callback) {
callback();
}
});
+
+ //
+ // Dereference `libev` so that this connection
+ // does not keep the event loop alive, create ghost-nodes
+ // this forces process.nextTick (above) to fire
+ // and unreferences the runMain() from above
+ //
+ evref.unref();
return carapace;
-};
+};
View
1 test/helper/macros.js
@@ -98,7 +98,6 @@ macros.assertSpawn = function (PORT, script, argv, vows) {
},
"should respond with the proper wrapped script output": function (_, child, data) {
assert.notEqual(data.toString().indexOf(script), -1);
- assert.isTrue(true);
}
}

0 comments on commit ce14bfe

Please sign in to comment.
Something went wrong with that request. Please try again.