Skip to content

Commit

Permalink
Update tests to work with module contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jul 15, 2010
1 parent 9472812 commit 9fd5e3c
Show file tree
Hide file tree
Showing 141 changed files with 624 additions and 499 deletions.
2 changes: 0 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
var path = require("path");

exports = module.exports = global;

exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, "fixtures");
exports.libDir = path.join(exports.testDir, "../lib");
Expand Down
4 changes: 2 additions & 2 deletions test/disabled/test-cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ var server = http.createServer(function (req, res) {
res.sendBody(body);
res.finish();
});
server.listen(PORT);
server.listen(common.PORT);

var errors = 0;
var successes = 0;

var promise = process.cat("http://localhost:"+PORT, "utf8");
var promise = process.cat("http://localhost:"+common.PORT, "utf8");

promise.addCallback(function (content) {
assert.equal(body, content);
Expand Down
3 changes: 2 additions & 1 deletion test/disabled/test-dns.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert

var dns = require("dns"),
child_process = require("child_process"),
Expand Down
3 changes: 2 additions & 1 deletion test/disabled/test-eio-race3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* XXX Can this test be modified to not call the now-removed wait()? */

require("../common");
common = require("../common");
assert = common.assert


console.log('first stat ...');
Expand Down
9 changes: 5 additions & 4 deletions test/disabled/test-fs-sendfile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require("../common");
common = require("../common");
assert = common.assert

tcp = require("tcp");
sys = require("sys");
var x = path.join(fixturesDir, "x.txt");
var x = path.join(common.fixturesDir, "x.txt");
var expected = "xyz";

var server = tcp.createServer(function (socket) {
Expand All @@ -14,9 +15,9 @@ var server = tcp.createServer(function (socket) {
assert.equal(expected, found);
});
});
server.listen(PORT);
server.listen(common.PORT);

var client = tcp.createConnection(PORT);
var client = tcp.createConnection(common.PORT);
client.addListener("connect", function () {
fs.open(x, 'r').addCallback(function (fd) {
fs.sendfile(client.fd, fd, 0, expected.length).addCallback(function (size) {
Expand Down
7 changes: 4 additions & 3 deletions test/disabled/test-http-big-proxy-responses.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../common');
common = require("../common");
assert = common.assert
var sys = require("sys"),
fs = require("fs"),
http = require("http"),
Expand Down Expand Up @@ -63,7 +64,7 @@ function call_chargen(list) {
if (list.length > 0) {
var len = list.shift();

sys.debug("calling chargen for " + len + " chunks.");
sys.common.debug("calling chargen for " + len + " chunks.");

var recved = 0;

Expand All @@ -78,7 +79,7 @@ function call_chargen(list) {

res.addListener('end', function() {
assert.ok(recved <= (len*chunk.length));
sys.debug("end for " + len + " chunks.");
sys.common.debug("end for " + len + " chunks.");
call_chargen(list);
});

Expand Down
7 changes: 4 additions & 3 deletions test/disabled/test-http-head-request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../common');
common = require("../common");
assert = common.assert

var assert = require("assert");
var http = require("http");
Expand All @@ -14,12 +15,12 @@ server = http.createServer(function (req, res) {
if (req.method != 'HEAD') res.write(body);
res.end();
});
server.listen(PORT);
server.listen(common.PORT);

var gotEnd = false;

server.addListener('listening', function() {
var client = http.createClient(PORT);
var client = http.createClient(common.PORT);
var request = client.request("HEAD", "/");
request.addListener('response', function (response) {
console.log('got response');
Expand Down
7 changes: 4 additions & 3 deletions test/disabled/test-http-stress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert

http = require("http");

Expand All @@ -10,14 +11,14 @@ var server = http.createServer(function(req, res) {
res.write(body);
res.end();
});
server.listen(PORT);
server.listen(common.PORT);

var requests_ok = 0;
var requests_complete = 0;

server.addListener('listening', function () {
for (var i = 0; i < request_count; i++) {
http.cat('http://localhost:'+PORT+'/', 'utf8', function (err, content) {
http.cat('http://localhost:'+common.PORT+'/', 'utf8', function (err, content) {
requests_complete++;
if (err) {
print("-");
Expand Down
3 changes: 2 additions & 1 deletion test/disabled/test-idle-watcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert

var complete = false;
var idle = new process.IdleWatcher();
Expand Down
2 changes: 1 addition & 1 deletion test/disabled/test-net-fd-passing.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function fdPassingTest(path, port) {
var message = "beep toot";
var expectedData = ["[greeting] " + greeting, "[echo] " + message];

var receiverArgs = [fixturesDir + "/net-fd-passing-receiver.js", path, greeting];
var receiverArgs = [common.fixturesDir + "/net-fd-passing-receiver.js", path, greeting];
var receiver = process.createChildProcess(process.ARGV[0], receiverArgs);

var initializeSender = function() {
Expand Down
9 changes: 5 additions & 4 deletions test/disabled/test-remote-module-loading.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert

var http = require('http');
var sys = require('sys');
Expand All @@ -14,16 +15,16 @@ var server = http.createServer(function(req, res) {
res.write(body);
res.end();
});
server.listen(PORT);
server.listen(common.PORT);

assert.throws(function () {
var httpModule = require('http://localhost:'+PORT+'/moduleA.js');
var httpModule = require('http://localhost:'+common.PORT+'/moduleA.js');
assert.equal('/moduleA.js', httpModule.httpPath());
modulesLoaded++;
});

var nodeBinary = process.ARGV[0];
var cmd = 'NODE_PATH='+libDir+' '+nodeBinary+' http://localhost:'+PORT+'/moduleB.js';
var cmd = 'NODE_PATH='+libDir+' '+nodeBinary+' http://localhost:'+common.PORT+'/moduleB.js';

sys.exec(cmd, function (err, stdout, stderr) {
if (err) throw err;
Expand Down
3 changes: 2 additions & 1 deletion test/disabled/test-setuidgid.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Requires special privlages
require('../common');
common = require("../common");
assert = common.assert
var assert = require('assert');

var oldgid = process.getgid();
Expand Down
7 changes: 4 additions & 3 deletions test/disabled/tls_client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../common');
common = require("../common");
assert = common.assert
var sys=require('sys');
var net=require('net');
var fs=require('fs');
Expand All @@ -8,7 +9,7 @@ var crypto=require('crypto');
var client = net.createConnection(443, "www.microsoft.com");
//var client = net.createConnection(443, "www.google.com");

var caPem = fs.readFileSync(fixturesDir+"/msca.pem");
var caPem = fs.readFileSync(common.fixturesDir+"/msca.pem");
//var caPem = fs.readFileSync("ca.pem");

var credentials = crypto.createCredentials({ca:caPem});
Expand All @@ -27,7 +28,7 @@ client.addListener("secure", function () {
});

client.addListener("data", function (chunk) {
sys.error(chunk);
sys.common.error(chunk);
});

client.addListener("end", function () {
Expand Down
7 changes: 4 additions & 3 deletions test/disabled/tls_server.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
require('../common');
common = require("../common");
assert = common.assert

var sys=require('sys');
var net=require('net');
var fs=require('fs');
var crypto=require('crypto');

var keyPem = fs.readFileSync(fixturesDir + "/cert.pem");
var certPem = fs.readFileSync(fixturesDir + "/cert.pem");
var keyPem = fs.readFileSync(common.fixturesDir + "/cert.pem");
var certPem = fs.readFileSync(common.fixturesDir + "/cert.pem");

var credentials = crypto.createCredentials({key:keyPem, cert:certPem});
var i = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/a.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var c = require("./b/c");

debug("load fixtures/a.js");
common.debug("load fixtures/a.js");

var string = "A";

Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/echo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert

print("hello world\r\n");

Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/print-chars-from-buffer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert
Buffer = require("buffer").Buffer;

var n = parseInt(process.argv[2]);
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/print-chars.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert

var n = parseInt(process.argv[2]);

Expand Down
3 changes: 2 additions & 1 deletion test/message/2100bytes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require('../common');
common = require("../common");
assert = common.assert

sys = require('sys');
console.log([
Expand Down
3 changes: 2 additions & 1 deletion test/message/hello_world.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('../common');
common = require("../common");
assert = common.assert

console.log('hello world');
7 changes: 4 additions & 3 deletions test/message/undefined_reference_in_new_context.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require('../common');
common = require("../common");
assert = common.assert

error('before');
common.error('before');

var Script = process.binding('evals').Script;

// undefined reference
script = new Script('foo.bar = 5;');
script.runInNewContext();

error('after');
common.error('after');
4 changes: 2 additions & 2 deletions test/message/undefined_reference_in_new_context.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
before


*test/message/undefined_reference_in_new_context.js:9
*test/message/undefined_reference_in_new_context.js:10
script.runInNewContext();
^
ReferenceError: foo is not defined
Expand All @@ -11,4 +11,4 @@ ReferenceError: foo is not defined
at Module._loadScriptSync (module:*)
at Module.loadSync (module:*)
at Object.runMain (module:*)
at node.js:*242:10
at node.js:*
3 changes: 2 additions & 1 deletion test/pummel/test-child-process-spawn-loop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert

var spawn = require('child_process').spawn;

Expand Down
7 changes: 4 additions & 3 deletions test/pummel/test-http-client-reconnect-bug.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert

var tcp = require("tcp"),
sys = require("sys"),
Expand All @@ -10,9 +11,9 @@ var eofCount = 0;
var server = tcp.createServer(function(socket) {
socket.end();
});
server.listen(PORT);
server.listen(common.PORT);

var client = http.createClient(PORT);
var client = http.createClient(common.PORT);

client.addListener("error", function() {
console.log("ERROR!");
Expand Down
7 changes: 4 additions & 3 deletions test/pummel/test-keep-alive.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This test requires the program "ab"
require("../common");
common = require("../common");
assert = common.assert
http = require("http");
exec = require("child_process").exec;

Expand All @@ -18,7 +19,7 @@ var normalReqSec = 0;


function runAb(opts, callback) {
var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/";
var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/";
exec(command, function (err, stdout, stderr) {
if (err) {
console.log("ab not installed? skipping test.\n" + stderr);
Expand All @@ -41,7 +42,7 @@ function runAb(opts, callback) {
});
}

server.listen(PORT, function () {
server.listen(common.PORT, function () {
runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) {
keepAliveReqSec = reqSec;
assert.equal(true, keepAliveRequests > 0);
Expand Down
9 changes: 5 additions & 4 deletions test/pummel/test-net-many-clients.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("../common");
common = require("../common");
assert = common.assert
net = require("net");
// settings
var bytes = 1024*40;
Expand All @@ -23,7 +24,7 @@ var server = net.createServer(function (c) {
});

function runClient (callback) {
var client = net.createConnection(PORT);
var client = net.createConnection(common.PORT);

client.connections = 0;

Expand Down Expand Up @@ -59,14 +60,14 @@ function runClient (callback) {
assert.ok(!client.fd);

if (this.connections < connections_per_client) {
this.connect(PORT);
this.connect(common.PORT);
} else {
callback();
}
});
}

server.listen(PORT, function () {
server.listen(common.PORT, function () {
var finished_clients = 0;
for (var i = 0; i < concurrency; i++) {
runClient(function () {
Expand Down
Loading

0 comments on commit 9fd5e3c

Please sign in to comment.