Browse files

Cleaned up the test cases

  • Loading branch information...
1 parent a4d461e commit c6a4cdc133350d57594f8958dc7d1306efd29a4b @fgnass committed Feb 7, 2012
Showing with 38 additions and 25 deletions.
  1. +6 −14 test/app.coffee
  2. +14 −0 test/cluster.coffee
  3. +6 −11 test/cluster.js
  4. +12 −0 test/server.js
View
20 test/app.coffee
@@ -1,22 +1,14 @@
http = require 'http'
message = require './message'
-server = http.createServer (req, resp, _) ->
- try
- resp.writeHead 200,
- 'Content-Type': 'text/plain'
+server = http.createServer (req, res) ->
+ res.writeHead 200,
+ 'Content-Type': 'text/plain'
- resp.write message
- resp.end '\n'
-
- catch err
- resp.writeHead 500,
- 'Content-Type': 'text/plain'
-
- resp.write err.toString()
- resp.end '\n'
+ res.write message
+ res.end '\n'
server.listen 8080
-console.log 'Listening at http://localhost:8080/ ...'
+console.log 'Server running at http://localhost:8080/'
console.log message
View
14 test/cluster.coffee
@@ -0,0 +1,14 @@
+cluster = require("cluster")
+http = require("http")
+if cluster.isMaster
+ i = 0
+
+ while i < 2
+ console.log "Forking worker", i
+ worker = cluster.fork()
+ worker.on "message", (msg) ->
+ console.log "Message from worker:", msg
+ i++
+else
+ process.send "*** Worker started! ***"
+ require "./server"
View
17 test/cluster.js
@@ -4,18 +4,13 @@ var http = require('http');
if (cluster.isMaster) {
for (var i = 0; i < 2; i++) {
console.log('Forking worker', i);
- cluster.fork();
+ var worker = cluster.fork();
+ worker.on('message', function(msg) {
+ console.log('Message from worker:', msg);
+ });
}
-
- cluster.on('death', function(worker) {
- console.log('worker ' + worker.pid + ' died');
- });
}
else {
- console.log('Worker started');
- // Worker processes have a http server.
- http.Server(function(req, res) {
- res.writeHead(200);
- res.end("hello world\n");
- }).listen(8000);
+ process.send('*** Worker started! ***');
+ require('./server');
}
View
12 test/server.js
@@ -0,0 +1,12 @@
+var http = require('http');
+var message = require('./message');
+
+var server = http.createServer(function (req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.write(message);
+ res.end('\n');
+});
+
+server.listen(8000);
+console.log('Server running at http://127.0.0.1:8000/');
+console.log(message);

0 comments on commit c6a4cdc

Please sign in to comment.