Created
April 16, 2013 22:23
-
-
Save leozc/5400166 to your computer and use it in GitHub Desktop.
This implementation simulates very very slow HTTP server
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 implementation simulates very very slow HTTP server | |
**/ | |
var http = require('http'); | |
var sleep = require('sleep'); | |
var fs = require('fs'); | |
var timeout = 1000; //sleep 1 seconds | |
var iteration = 100; //sleep 100 iteration | |
http.createServer(function (req, res) { | |
console.log("Request in"); | |
var myi = iteration | |
setTimeout(sleepMe, timeout); | |
function sleepMe() { | |
if(myi!=0){ | |
var response = new Date().toString() + ":"+myi.toString(); | |
console.log(response); | |
res.write(response); | |
myi--; | |
setTimeout(sleepMe,timeout); | |
}else | |
{ | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end("Hello I am awake"); | |
console.log("Request Done"); | |
} | |
} | |
}).listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use to test HTTP/Socket Timeout.