Permalink
Browse files

keeping database working accross test seems to be working, needs more…

… testing

there seems to be a few issues with catching some types of errors in the test server, need more testing/debugging
  • Loading branch information...
1 parent fea7b9a commit dc0cfe1a71ff2fe6635e18d5787f114ae6dd32b9 @matthewfl committed Dec 28, 2010
Showing with 24 additions and 18 deletions.
  1. +3 −1 Bespin/control.js
  2. +3 −3 config.sample.js
  3. +2 −1 front-end.js
  4. +1 −1 production.js
  5. +1 −3 sandbox/modules.js
  6. +14 −9 test.js
View
@@ -301,7 +301,9 @@ exports.testCommand = function (args, request) {
var win = window.open("");
Ajax.Call({
"action": "test",
- "code": env.editor.value
+ "code": env.editor.value,
+ "randToken": randomToken,
+ "fileName": loadFile
}, function (p) {
win.location.href=p;
});
View
@@ -12,11 +12,11 @@ exports.checkOkCode = "Random Check Ok Code";
exports.testPort=8090;
-exports.testBase="##.test.jsapp.us"; // "##.localhost:8090"
+exports.testBase=".test.jsapp.us"; // "##.localhost:8090"
exports.testHost="node_test_host_id";
exports.testSKey="sampleKey"; // https://www.random.org/passwords/?num=1&len=24&format=plain&rnd=new
-exports.testTimeToLive=5*60*1000; // in ms
-exports.testDoNotOverwrite=true; // should be true in production
+exports.testTimeToLive=15*60*1000; // in ms
+//exports.testDoNotOverwrite=true; // should be true in production
exports.errorPage="http://jsapp.us/error";
View
@@ -3,6 +3,7 @@ var querystring = require('querystring');
var http = require('http');
var fs = require('fs');
var dns = require('dns');
+var querystring = require('querystring');
var router = require('./lib/node-router');
var server = router.getServer();
@@ -66,7 +67,7 @@ var ajaxActions = {
test: function (data, user, back) {
try {
var con = http.createClient(config.testPort, 'localhost');
- var r = con.request('POST', '/?key='+config.testSKey+'&user='+user, {
+ var r = con.request('POST', '/?'+querystring.stringify({"key":config.testSKey,"token":data.randToken,"file":data.fileName,"user":user}), {
"host": config.testHost
}, {'Content-Length': data.code.length});
r.on('response', function (response) {
View
@@ -12,7 +12,7 @@ var server = http.createServer(function (req, res) {
boxes[req.headers.host].server(req,res);
}else{
var hostBase = req.headers.host.replace(config.productionBase, "");
- console.log(hostBase);
+ console.log(req.headers.host);
db.get(hostBase != req.headers.host ? ("app_" + hostBase) : ("app_"+req.headers.host), function (code) {
console.log(code);
if(!code) {
View
@@ -71,9 +71,7 @@ var db;
exports.db = exports.database = function (context, config) {
db = db || require('../db');
var baseName = "db_"+config.user+"_"+config.name+"_";
- var tmp={};
- console.log(config);
- console.log(baseName)
+ var tmp=config._tmp_db;
return {
get: function (name, back) {
if(config.test && tmp[name]) back(tmp[name]);
View
23 test.js
@@ -17,22 +17,27 @@ var server = http.createServer(function (req, res) {
});
req.on('end', function () {
var urlInfo = urlParse(req.url, true);
- console.log(data, urlInfo.query.user, urlInfo.query.app);
+ console.log(data, urlInfo.query.user, urlInfo.query.file, req.url);
if(urlInfo.query.key != config.testSKey) {
res.write("This test server has expired");
res.end();
return;
}
sandbox.build(data, urlInfo.query.user, function (d) {
var name;
- do {
- name = config.testBase.replace(/\#\#/g, Math.random().toString().substring(2,12));
- }while(boxes[name] && config.testDoNotOverwrite);
- boxes[name] = new sandbox.SandBox(d, {test: true, user: urlInfo.query.user || null, app: urlInfo.query.app || null});
- if(config.testDoNotOverwrite) // if overwritable, then no need to keep clean
- setTimeout(function () {
- boxes[name] =null;
- }, config.testTimeToLive);
+ if(urlInfo.query.user && urlInfo.query.user != "null" && urlInfo.query.file && urlInfo.query.file != "null")
+ name = urlInfo.query.token+"."+urlInfo.query.file+"."+urlInfo.query.user+config.testBase;
+ else
+ name = Math.random().toString().substring(2,12) + config.testBase;
+ var tmp_db={};
+ if(boxes[name]) {
+ clearTimeout(boxes[name]._timer);
+ tmp_db=boxes[name].config._tmp_db;
+ }
+ boxes[name] = new sandbox.SandBox(d, {test: true, user: urlInfo.query.user || null, name: urlInfo.query.fileName || null, _tmp_db: tmp_db});
+ boxes[name]._timer = setTimeout(function () {
+ boxes[name] =null;
+ }, config.testTimeToLive);
res.write("http://"+name /* + ":8000" for testing */);
if(boxes[name].error) res.write("\nerror\n");
res.end();

0 comments on commit dc0cfe1

Please sign in to comment.