diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-28 13:14:53 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-28 13:14:53 -0700 |
commit | c03550de3598e3c55ea6c181148286b8673b6df1 (patch) | |
tree | 10f0fa1e682ce26dd022e79268173f3e90bc85f2 /tests/http | |
parent | c6a918d9962dcf2354483b709b8bf0fffbbc3983 (diff) | |
download | infinitytier-c03550de3598e3c55ea6c181148286b8673b6df1.tar.gz infinitytier-c03550de3598e3c55ea6c181148286b8673b6df1.zip |
HTTP test works!
Diffstat (limited to 'tests/http')
-rw-r--r-- | tests/http/agent.js | 16 | ||||
-rw-r--r-- | tests/http/server.js | 14 |
2 files changed, 22 insertions, 8 deletions
diff --git a/tests/http/agent.js b/tests/http/agent.js index 14964d87..34837411 100644 --- a/tests/http/agent.js +++ b/tests/http/agent.js @@ -9,14 +9,14 @@ var RUN_TEST_EVERY = 1000; var TEST_DURATION = (60 * 1000); // Where should I contact to register and query a list of other nodes? -var SERVER_HOST = '127.0.0.1'; +var SERVER_HOST = '174.136.102.178'; var SERVER_PORT = 18080; // Which port should agents use for their HTTP? var AGENT_PORT = 18888; // Payload size in bytes -var PAYLOAD_SIZE = 4096; +var PAYLOAD_SIZE = 100000; // --------------------------------------------------------------------------- @@ -66,9 +66,9 @@ if (thisAgentId === null) { //console.log(thisAgentId); // Create a random (and therefore not very compressable) payload -var payload = ''; -while (payload.length < PAYLOAD_SIZE) { - payload += String.fromCharCode(Math.round(Math.random() * 255.0)); +var payload = new Buffer(PAYLOAD_SIZE); +for(var xx=0;xx<PAYLOAD_SIZE;++xx) { + payload.writeUInt8(Math.round(Math.random() * 255.0),xx); } // Incremented for each test @@ -147,7 +147,9 @@ function performTestOnAllPeers(peers,callback) path: '/' },function(res) { var bytes = 0; - res.on('data',function(chunk) { bytes += chunk.length; }); + res.on('data',function(chunk) { + bytes += chunk.length; + }); res.on('end',function() { if (timedOut) return next(null); @@ -204,7 +206,7 @@ var expressServer = app.listen(AGENT_PORT,function () { } performTestOnAllPeers(peers,function(results) { - console.log(results); + //console.log(results); var submit = http.request({ host: SERVER_HOST, diff --git a/tests/http/server.js b/tests/http/server.js index 221dcda9..a58756bc 100644 --- a/tests/http/server.js +++ b/tests/http/server.js @@ -5,6 +5,8 @@ var SERVER_PORT = 18080; // --------------------------------------------------------------------------- +var fs = require('fs'); + var express = require('express'); var app = express(); @@ -28,6 +30,8 @@ app.post('/:agentId',function(req,res) { var agentId = req.params.agentId; if ((!agentId)||(agentId.length !== 32)) return res.status(404).send(''); + + var receiveTime = Date.now(); var resultData = null; try { resultData = JSON.parse(req.rawBody); @@ -36,9 +40,17 @@ app.post('/:agentId',function(req,res) { } result = { agentId: agentId, + receiveTime: receiveTime, result: resultData }; - console.log(result); + + var nows = receiveTime.toString(16); + while (nows.length < 16) + nows = '0' + nows; + fs.writeFile('result_'+agentId+'_'+nows,JSON.stringify(result),function(err) { + console.log(result); + }); + return res.status(200).send(''); }); |