diff --git a/src/node.js b/src/node.js index 73a23d26f5..ec4dc7ba48 100644 --- a/src/node.js +++ b/src/node.js @@ -126,7 +126,13 @@ node.Module.prototype.load = function (callback) { self.onExit = self.target.__onExit; self.waitChildrenLoad(function () { - if (self.onLoad) self.onLoad(); + if (self.onLoad) { + node.stdio.writeError( "(node) onLoad is depreciated it will be " + + "removed in the future. Don't want it to " + + "leave? Discuss on mailing list.\n" + ); + self.onLoad(); + } self.loaded = true; loadPromise.emitSuccess([self.target]); }); diff --git a/test/mjsunit/test-encode-utf8.js b/test/mjsunit/test-encode-utf8.js index 461b8956fa..9e63cbe08b 100644 --- a/test/mjsunit/test-encode-utf8.js +++ b/test/mjsunit/test-encode-utf8.js @@ -1,11 +1,9 @@ include("mjsunit.js"); -function onLoad () { - var a = [116,101,115,116,32,206,163,207,131,207,128,206,177,32,226,161,140,226,160, 129,226,160,167,226,160,145]; - var s = node.encodeUtf8(a); - assertEquals("test Σσπα ⡌⠁⠧⠑", s); +var a = [116,101,115,116,32,206,163,207,131,207,128,206,177,32,226,161,140,226,160, 129,226,160,167,226,160,145]; +var s = node.encodeUtf8(a); +assertEquals("test Σσπα ⡌⠁⠧⠑", s); - a = [104, 101, 108, 108, 111]; - s = node.encodeUtf8(a); - assertEquals("hello", s); -} +a = [104, 101, 108, 108, 111]; +s = node.encodeUtf8(a); +assertEquals("hello", s); diff --git a/test/mjsunit/test-event-emitter-add-listeners.js b/test/mjsunit/test-event-emitter-add-listeners.js index 21a140f4d6..f3d88e26aa 100644 --- a/test/mjsunit/test-event-emitter-add-listeners.js +++ b/test/mjsunit/test-event-emitter-add-listeners.js @@ -5,23 +5,21 @@ var e = new node.EventEmitter(); var events_new_listener_emited = []; var times_hello_emited = 0; -function onLoad () { - e.addListener("newListener", function (event, listener) { - puts("newListener: " + event); - events_new_listener_emited.push(event); - }); - - e.addListener("hello", function (a, b) { - puts("hello"); - times_hello_emited += 1 - assertEquals("a", a); - assertEquals("b", b); - }); - - puts("start"); - - e.emit("hello", ["a", "b"]); -} +e.addListener("newListener", function (event, listener) { + puts("newListener: " + event); + events_new_listener_emited.push(event); +}); + +e.addListener("hello", function (a, b) { + puts("hello"); + times_hello_emited += 1 + assertEquals("a", a); + assertEquals("b", b); +}); + +puts("start"); + +e.emit("hello", ["a", "b"]); function onExit () { assertArrayEquals(["hello"], events_new_listener_emited); diff --git a/test/mjsunit/test-file-cat-noexist.js b/test/mjsunit/test-file-cat-noexist.js index c1a415b419..e36a21810f 100644 --- a/test/mjsunit/test-file-cat-noexist.js +++ b/test/mjsunit/test-file-cat-noexist.js @@ -1,22 +1,20 @@ include("mjsunit.js"); var got_error = false; -function onLoad () { - var dirname = node.path.dirname(__filename); - var fixtures = node.path.join(dirname, "fixtures"); - var filename = node.path.join(fixtures, "does_not_exist.txt"); - var promise = node.fs.cat(filename, "raw"); - - promise.addCallback(function (content) { - node.debug("cat returned some content: " + content); - node.debug("this shouldn't happen as the file doesn't exist..."); - assertTrue(false); - }); +var dirname = node.path.dirname(__filename); +var fixtures = node.path.join(dirname, "fixtures"); +var filename = node.path.join(fixtures, "does_not_exist.txt"); +var promise = node.fs.cat(filename, "raw"); - promise.addErrback(function () { - got_error = true; - }); -} +promise.addCallback(function (content) { + node.debug("cat returned some content: " + content); + node.debug("this shouldn't happen as the file doesn't exist..."); + assertTrue(false); +}); + +promise.addErrback(function () { + got_error = true; +}); function onExit () { assertTrue(got_error); diff --git a/test/mjsunit/test-http-cat.js b/test/mjsunit/test-http-cat.js index 2e26a01c29..e219c1ce75 100644 --- a/test/mjsunit/test-http-cat.js +++ b/test/mjsunit/test-http-cat.js @@ -16,19 +16,17 @@ server.listen(PORT); var got_good_server_content = false; var bad_server_got_error = false; -function onLoad () { - node.http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) { - puts("got response"); - got_good_server_content = true; - assertEquals(body, content); - server.close(); - }); - - node.http.cat("http://localhost:12312/", "utf8").addErrback(function () { - puts("got error (this should happen)"); - bad_server_got_error = true; - }); -} +node.http.cat("http://localhost:"+PORT+"/", "utf8").addCallback(function (content) { + puts("got response"); + got_good_server_content = true; + assertEquals(body, content); + server.close(); +}); + +node.http.cat("http://localhost:12312/", "utf8").addErrback(function () { + puts("got error (this should happen)"); + bad_server_got_error = true; +}); function onExit () { assertTrue(got_good_server_content); diff --git a/test/mjsunit/test-http-client-upload.js b/test/mjsunit/test-http-client-upload.js index 2ea8f0adef..2ad0610fd5 100644 --- a/test/mjsunit/test-http-client-upload.js +++ b/test/mjsunit/test-http-client-upload.js @@ -24,26 +24,24 @@ var server = node.http.createServer(function(req, res) { }); server.listen(PORT); -function onLoad () { - var client = node.http.createClient(PORT); - var req = client.post('/'); - - req.sendBody('1\n'); - req.sendBody('2\n'); - req.sendBody('3\n'); - - puts("client finished sending request"); - req.finish(function(res) { - res.setBodyEncoding("utf8"); - res.addListener('body', function(chunk) { - puts(chunk); - }); - res.addListener('complete', function() { - client_res_complete = true; - server.close(); - }); +var client = node.http.createClient(PORT); +var req = client.post('/'); + +req.sendBody('1\n'); +req.sendBody('2\n'); +req.sendBody('3\n'); + +puts("client finished sending request"); +req.finish(function(res) { + res.setBodyEncoding("utf8"); + res.addListener('body', function(chunk) { + puts(chunk); }); -} + res.addListener('complete', function() { + client_res_complete = true; + server.close(); + }); +}); function onExit () { assertEquals("1\n2\n3\n", sent_body); diff --git a/test/mjsunit/test-http-proxy.js b/test/mjsunit/test-http-proxy.js index 2df51ddc2a..3511487097 100644 --- a/test/mjsunit/test-http-proxy.js +++ b/test/mjsunit/test-http-proxy.js @@ -32,22 +32,20 @@ proxy.listen(PROXY_PORT); var body = ""; -function onLoad () { - var client = node.http.createClient(PROXY_PORT); - var req = client.get("/test"); - // node.debug("client req") - req.finish(function (res) { - // node.debug("got res"); - assertEquals(200, res.statusCode); - res.setBodyEncoding("utf8"); - res.addListener("body", function (chunk) { body += chunk; }); - res.addListener("complete", function () { - proxy.close(); - backend.close(); - // node.debug("closed both"); - }); +var client = node.http.createClient(PROXY_PORT); +var req = client.get("/test"); +// node.debug("client req") +req.finish(function (res) { + // node.debug("got res"); + assertEquals(200, res.statusCode); + res.setBodyEncoding("utf8"); + res.addListener("body", function (chunk) { body += chunk; }); + res.addListener("complete", function () { + proxy.close(); + backend.close(); + // node.debug("closed both"); }); -} +}); function onExit () { assertEquals(body, "hello world\n"); diff --git a/test/mjsunit/test-http-server.js b/test/mjsunit/test-http-server.js index ac04d5bfbb..9074b1b446 100644 --- a/test/mjsunit/test-http-server.js +++ b/test/mjsunit/test-http-server.js @@ -7,60 +7,57 @@ var requests_sent = 0; var server_response = ""; var client_got_eof = false; -function onLoad() { - - node.http.createServer(function (req, res) { - res.id = request_number; - req.id = request_number++; - - if (req.id == 0) { - assertEquals("GET", req.method); - assertEquals("/hello", req.uri.path); - } - - if (req.id == 1) { - assertEquals("POST", req.method); - assertEquals("/quit", req.uri.path); - this.close(); - //puts("server closed"); - } - - setTimeout(function () { - res.sendHeader(200, {"Content-Type": "text/plain"}); - res.sendBody(req.uri.path); - res.finish(); - }, 1); - - }).listen(port); - - var c = node.tcp.createConnection(port); +node.http.createServer(function (req, res) { + res.id = request_number; + req.id = request_number++; + + if (req.id == 0) { + assertEquals("GET", req.method); + assertEquals("/hello", req.uri.path); + } + + if (req.id == 1) { + assertEquals("POST", req.method); + assertEquals("/quit", req.uri.path); + this.close(); + //puts("server closed"); + } + + setTimeout(function () { + res.sendHeader(200, {"Content-Type": "text/plain"}); + res.sendBody(req.uri.path); + res.finish(); + }, 1); + +}).listen(port); + +var c = node.tcp.createConnection(port); + +c.setEncoding("utf8"); + +c.addListener("connect", function () { + c.send( "GET /hello HTTP/1.1\r\n\r\n" ); + requests_sent += 1; +}); + +c.addListener("receive", function (chunk) { + server_response += chunk; + + if (requests_sent == 1) { + c.send("POST /quit HTTP/1.1\r\n\r\n"); + c.close(); + assertEquals(c.readyState, "readOnly"); + requests_sent += 1; + } +}); - c.setEncoding("utf8"); +c.addListener("eof", function () { + client_got_eof = true; +}); - c.addListener("connect", function () { - c.send( "GET /hello HTTP/1.1\r\n\r\n" ); - requests_sent += 1; - }); - - c.addListener("receive", function (chunk) { - server_response += chunk; - - if (requests_sent == 1) { - c.send("POST /quit HTTP/1.1\r\n\r\n"); - c.close(); - assertEquals(c.readyState, "readOnly"); - requests_sent += 1; - } - }); - - c.addListener("eof", function () { - client_got_eof = true; - }); - - c.addListener("close", function () { - assertEquals(c.readyState, "closed"); - }); -} +c.addListener("close", function () { + assertEquals(c.readyState, "closed"); +}); function onExit () { assertEquals(2, request_number); diff --git a/test/mjsunit/test-http.js b/test/mjsunit/test-http.js index d726dd2913..e92a410121 100644 --- a/test/mjsunit/test-http.js +++ b/test/mjsunit/test-http.js @@ -6,57 +6,55 @@ var responses_recvd = 0; var body0 = ""; var body1 = ""; -function onLoad () { - node.http.createServer(function (req, res) { - if (responses_sent == 0) { - assertEquals("GET", req.method); - assertEquals("/hello", req.uri.path); +node.http.createServer(function (req, res) { + if (responses_sent == 0) { + assertEquals("GET", req.method); + assertEquals("/hello", req.uri.path); - p(req.headers); - assertTrue("Accept" in req.headers); - assertEquals("*/*", req.headers["Accept"]); + p(req.headers); + assertTrue("Accept" in req.headers); + assertEquals("*/*", req.headers["Accept"]); - assertTrue("Foo" in req.headers); - assertEquals("bar", req.headers["Foo"]); - } + assertTrue("Foo" in req.headers); + assertEquals("bar", req.headers["Foo"]); + } - if (responses_sent == 1) { - assertEquals("POST", req.method); - assertEquals("/world", req.uri.path); - this.close(); - } + if (responses_sent == 1) { + assertEquals("POST", req.method); + assertEquals("/world", req.uri.path); + this.close(); + } - req.addListener("complete", function () { - res.sendHeader(200, {"Content-Type": "text/plain"}); - res.sendBody("The path was " + req.uri.path); - res.finish(); - responses_sent += 1; - }); + req.addListener("complete", function () { + res.sendHeader(200, {"Content-Type": "text/plain"}); + res.sendBody("The path was " + req.uri.path); + res.finish(); + responses_sent += 1; + }); + + //assertEquals("127.0.0.1", res.connection.remoteAddress); +}).listen(PORT); - //assertEquals("127.0.0.1", res.connection.remoteAddress); - }).listen(PORT); +var client = node.http.createClient(PORT); +var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"}); +req.finish(function (res) { + assertEquals(200, res.statusCode); + responses_recvd += 1; + res.setBodyEncoding("ascii"); + res.addListener("body", function (chunk) { body0 += chunk; }); + node.debug("Got /hello response"); +}); - var client = node.http.createClient(PORT); - var req = client.get("/hello", {"Accept": "*/*", "Foo": "bar"}); +setTimeout(function () { + req = client.post("/world"); req.finish(function (res) { assertEquals(200, res.statusCode); responses_recvd += 1; - res.setBodyEncoding("ascii"); - res.addListener("body", function (chunk) { body0 += chunk; }); - node.debug("Got /hello response"); + res.setBodyEncoding("utf8"); + res.addListener("body", function (chunk) { body1 += chunk; }); + node.debug("Got /world response"); }); - - setTimeout(function () { - req = client.post("/world"); - req.finish(function (res) { - assertEquals(200, res.statusCode); - responses_recvd += 1; - res.setBodyEncoding("utf8"); - res.addListener("body", function (chunk) { body1 += chunk; }); - node.debug("Got /world response"); - }); - }, 1); -} +}, 1); function onExit () { node.debug("responses_recvd: " + responses_recvd); diff --git a/test/mjsunit/test-module-loading.js b/test/mjsunit/test-module-loading.js index ef3647f1c5..661ea12b82 100644 --- a/test/mjsunit/test-module-loading.js +++ b/test/mjsunit/test-module-loading.js @@ -3,24 +3,22 @@ var a = require("fixtures/a.js"); var d = require("fixtures/b/d.js"); var d2 = require("fixtures/b/d.js"); -function onLoad () { - assertFalse(false, "testing the test program."); +assertFalse(false, "testing the test program."); - assertInstanceof(a.A, Function); - assertEquals("A", a.A()); +assertInstanceof(a.A, Function); +assertEquals("A", a.A()); - assertInstanceof(a.C, Function); - assertEquals("C", a.C()); +assertInstanceof(a.C, Function); +assertEquals("C", a.C()); - assertInstanceof(a.D, Function); - assertEquals("D", a.D()); +assertInstanceof(a.D, Function); +assertEquals("D", a.D()); - assertInstanceof(d.D, Function); - assertEquals("D", d.D()); +assertInstanceof(d.D, Function); +assertEquals("D", d.D()); - assertInstanceof(d2.D, Function); - assertEquals("D", d2.D()); -} +assertInstanceof(d2.D, Function); +assertEquals("D", d2.D()); function onExit () { assertInstanceof(a.A, Function); diff --git a/test/mjsunit/test-node-cat.js b/test/mjsunit/test-node-cat.js index 1467e01031..b6d7eb546c 100644 --- a/test/mjsunit/test-node-cat.js +++ b/test/mjsunit/test-node-cat.js @@ -18,34 +18,32 @@ server.listen(PORT); var errors = 0; var successes = 0; -function onLoad () { - var promise = node.cat("http://localhost:"+PORT, "utf8"); - - promise.addCallback(function (content) { - assertEquals(body, content); - server.close(); - successes += 1; - }); +var promise = node.cat("http://localhost:"+PORT, "utf8"); - promise.addErrback(function () { - errors += 1; - }); - - var dirname = node.path.dirname(__filename); - var fixtures = node.path.join(dirname, "fixtures"); - var x = node.path.join(fixtures, "x.txt"); - - promise = node.cat(x, "utf8"); - - promise.addCallback(function (content) { - assertEquals("xyz", content.replace(/[\r\n]/, '')); - successes += 1; - }); +promise.addCallback(function (content) { + assertEquals(body, content); + server.close(); + successes += 1; +}); - promise.addErrback(function () { - errors += 1; - }); -} +promise.addErrback(function () { + errors += 1; +}); + +var dirname = node.path.dirname(__filename); +var fixtures = node.path.join(dirname, "fixtures"); +var x = node.path.join(fixtures, "x.txt"); + +promise = node.cat(x, "utf8"); + +promise.addCallback(function (content) { + assertEquals("xyz", content.replace(/[\r\n]/, '')); + successes += 1; +}); + +promise.addErrback(function () { + errors += 1; +}); function onExit () { assertEquals(2, successes); diff --git a/test/mjsunit/test-process-buffering.js b/test/mjsunit/test-process-buffering.js index 75438cdc24..5d7ca4e56f 100644 --- a/test/mjsunit/test-process-buffering.js +++ b/test/mjsunit/test-process-buffering.js @@ -18,13 +18,11 @@ function pwd (callback) { } -function onLoad () { - pwd(function (result) { - p(result); - assertTrue(result.length > 1); - assertEquals("\n", result[result.length-1]); - }); -} +pwd(function (result) { + p(result); + assertTrue(result.length > 1); + assertEquals("\n", result[result.length-1]); +}); function onExit () { assertTrue(pwd_called); diff --git a/test/mjsunit/test-process-kill.js b/test/mjsunit/test-process-kill.js index b3e5ffc228..4f6fe23b97 100644 --- a/test/mjsunit/test-process-kill.js +++ b/test/mjsunit/test-process-kill.js @@ -2,15 +2,13 @@ include("mjsunit.js"); var exit_status = -1; -function onLoad () { - var cat = node.createProcess("cat"); +var cat = node.createProcess("cat"); - cat.addListener("output", function (chunk) { assertEquals(null, chunk); }); - cat.addListener("error", function (chunk) { assertEquals(null, chunk); }); - cat.addListener("exit", function (status) { exit_status = status; }); +cat.addListener("output", function (chunk) { assertEquals(null, chunk); }); +cat.addListener("error", function (chunk) { assertEquals(null, chunk); }); +cat.addListener("exit", function (status) { exit_status = status; }); - cat.kill(); -} +cat.kill(); function onExit () { assertTrue(exit_status > 0); diff --git a/test/mjsunit/test-process-simple.js b/test/mjsunit/test-process-simple.js index 9d68b7db51..42c130b898 100644 --- a/test/mjsunit/test-process-simple.js +++ b/test/mjsunit/test-process-simple.js @@ -24,11 +24,9 @@ cat.addListener("exit", function (status) { exit_status = status; }); -function onLoad () { - cat.write("hello"); - cat.write(" "); - cat.write("world"); -} +cat.write("hello"); +cat.write(" "); +cat.write("world"); function onExit () { assertEquals(0, exit_status); diff --git a/test/mjsunit/test-process-spawn-loop.js b/test/mjsunit/test-process-spawn-loop.js index db900730c5..f9583f7d9b 100644 --- a/test/mjsunit/test-process-spawn-loop.js +++ b/test/mjsunit/test-process-spawn-loop.js @@ -20,9 +20,7 @@ function spawn (i) { }); } -function onLoad () { - spawn(0); -} +spawn(0); function onExit () { assertTrue(finished); diff --git a/test/mjsunit/test-promise-wait.js b/test/mjsunit/test-promise-wait.js index 02d7ea32bd..1ef75c15f9 100644 --- a/test/mjsunit/test-promise-wait.js +++ b/test/mjsunit/test-promise-wait.js @@ -44,36 +44,34 @@ p5.addCallback(function () { }, 100); }); -function onLoad () { - p2.emitSuccess(); +p2.emitSuccess(); - assertFalse(p1_done); - assertTrue(p2_done); - assertFalse(p3_done); +assertFalse(p1_done); +assertTrue(p2_done); +assertFalse(p3_done); - var ret1 = p1.wait() - assertEquals("single arg", ret1); +var ret1 = p1.wait() +assertEquals("single arg", ret1); - assertTrue(p1_done); - assertTrue(p2_done); - assertFalse(p3_done); +assertTrue(p1_done); +assertTrue(p2_done); +assertFalse(p3_done); - p3.emitSuccess(); +p3.emitSuccess(); - assertFalse(p4_done); - assertFalse(p5_done); +assertFalse(p4_done); +assertFalse(p5_done); - p5.emitSuccess(); +p5.emitSuccess(); - assertFalse(p4_done); - assertTrue(p5_done); +assertFalse(p4_done); +assertTrue(p5_done); - var ret4 = p4.wait(); - assertArrayEquals(["a","b","c"], ret4); - - assertTrue(p4_done); -} +var ret4 = p4.wait(); +assertArrayEquals(["a","b","c"], ret4); + +assertTrue(p4_done); function onExit() { assertTrue(p1_done); diff --git a/test/mjsunit/test-remote-module-loading.js b/test/mjsunit/test-remote-module-loading.js index 91742d34a8..cead6d6bb0 100644 --- a/test/mjsunit/test-remote-module-loading.js +++ b/test/mjsunit/test-remote-module-loading.js @@ -12,8 +12,6 @@ s.listen(8000); include("mjsunit.js"); var a = require("http://localhost:8000/") -function onLoad() { - assertInstanceof(a.A, Function); - assertEquals("A", a.A()); - s.close(); -} +assertInstanceof(a.A, Function); +assertEquals("A", a.A()); +s.close(); diff --git a/test/mjsunit/test-tcp-many-clients.js b/test/mjsunit/test-tcp-many-clients.js index 624513254c..ee168065b7 100644 --- a/test/mjsunit/test-tcp-many-clients.js +++ b/test/mjsunit/test-tcp-many-clients.js @@ -55,13 +55,11 @@ function runClient (callback) { } -function onLoad () { - var finished_clients = 0; - for (var i = 0; i < concurrency; i++) { - runClient(function () { - if (++finished_clients == concurrency) server.close(); - }); - } +var finished_clients = 0; +for (var i = 0; i < concurrency; i++) { + runClient(function () { + if (++finished_clients == concurrency) server.close(); + }); } function onExit () { diff --git a/test/mjsunit/test-tcp-pingpong-delay.js b/test/mjsunit/test-tcp-pingpong-delay.js index 8b8d6cf5d6..cadd615537 100644 --- a/test/mjsunit/test-tcp-pingpong-delay.js +++ b/test/mjsunit/test-tcp-pingpong-delay.js @@ -83,9 +83,7 @@ function pingPongTest (port, host, on_complete) { }); } -function onLoad () { - pingPongTest(21988); -} +pingPongTest(21988); function onExit () { assertEquals(1, tests_run); diff --git a/test/mjsunit/test-tcp-pingpong.js b/test/mjsunit/test-tcp-pingpong.js index 448f05d438..20e3236840 100644 --- a/test/mjsunit/test-tcp-pingpong.js +++ b/test/mjsunit/test-tcp-pingpong.js @@ -77,12 +77,10 @@ function pingPongTest (port, host, on_complete) { }); } -function onLoad () { - /* All are run at once, so run on different ports */ - pingPongTest(20989, "localhost"); - pingPongTest(20988, null); - pingPongTest(20997, "::1"); -} +/* All are run at once, so run on different ports */ +pingPongTest(20989, "localhost"); +pingPongTest(20988, null); +pingPongTest(20997, "::1"); function onExit () { assertEquals(3, tests_run); diff --git a/test/mjsunit/test-tcp-raw.js b/test/mjsunit/test-tcp-raw.js index 6dc73cd990..d33132b769 100644 --- a/test/mjsunit/test-tcp-raw.js +++ b/test/mjsunit/test-tcp-raw.js @@ -14,29 +14,27 @@ echoServer.listen(PORT); var recv = []; var j = 0; -function onLoad () { - var c = node.tcp.createConnection(PORT); +var c = node.tcp.createConnection(PORT); - c.addListener("receive", function (chunk) { - if (++j < 256) { - c.send([j], "raw"); - } else { - c.close(); - } - for (var i = 0; i < chunk.length; i++) { - recv.push(chunk[i]); - } - }); - - c.addListener("connect", function () { +c.addListener("receive", function (chunk) { + if (++j < 256) { c.send([j], "raw"); - }); + } else { + c.close(); + } + for (var i = 0; i < chunk.length; i++) { + recv.push(chunk[i]); + } +}); - c.addListener("close", function () { - p(recv); - echoServer.close(); - }); -}; +c.addListener("connect", function () { + c.send([j], "raw"); +}); + +c.addListener("close", function () { + p(recv); + echoServer.close(); +}); function onExit () { var expected = []; diff --git a/test/mjsunit/test-tcp-reconnect.js b/test/mjsunit/test-tcp-reconnect.js index 379b0c2681..6b40cc96c8 100644 --- a/test/mjsunit/test-tcp-reconnect.js +++ b/test/mjsunit/test-tcp-reconnect.js @@ -6,48 +6,45 @@ var c = 0; var client_recv_count = 0; var disconnect_count = 0; -function onLoad () { - - var server = node.tcp.createServer(function (socket) { - socket.addListener("connect", function () { - socket.send("hello\r\n"); - }); - - socket.addListener("eof", function () { - socket.close(); - }); - - socket.addListener("close", function (had_error) { - //puts("server had_error: " + JSON.stringify(had_error)); - assertFalse(had_error); - }); - }); - server.listen(port); - - var client = node.tcp.createConnection(port); - - client.setEncoding("UTF8"); - - client.addListener("connect", function () { - puts("client connected."); +var server = node.tcp.createServer(function (socket) { + socket.addListener("connect", function () { + socket.send("hello\r\n"); }); - client.addListener("receive", function (chunk) { - client_recv_count += 1; - puts("client_recv_count " + client_recv_count); - assertEquals("hello\r\n", chunk); - client.close(); + socket.addListener("eof", function () { + socket.close(); }); - client.addListener("close", function (had_error) { - puts("disconnect"); + socket.addListener("close", function (had_error) { + //puts("server had_error: " + JSON.stringify(had_error)); assertFalse(had_error); - if (disconnect_count++ < N) - client.connect(port); // reconnect - else - server.close(); }); -} +}); +server.listen(port); + +var client = node.tcp.createConnection(port); + +client.setEncoding("UTF8"); + +client.addListener("connect", function () { + puts("client connected."); +}); + +client.addListener("receive", function (chunk) { + client_recv_count += 1; + puts("client_recv_count " + client_recv_count); + assertEquals("hello\r\n", chunk); + client.close(); +}); + +client.addListener("close", function (had_error) { + puts("disconnect"); + assertFalse(had_error); + if (disconnect_count++ < N) + client.connect(port); // reconnect + else + server.close(); +}); function onExit () { assertEquals(N+1, disconnect_count); diff --git a/test/mjsunit/test-tcp-throttle-kernel-buffer.js b/test/mjsunit/test-tcp-throttle-kernel-buffer.js index 7092b7390a..1cca5584e8 100644 --- a/test/mjsunit/test-tcp-throttle-kernel-buffer.js +++ b/test/mjsunit/test-tcp-throttle-kernel-buffer.js @@ -23,33 +23,31 @@ chars_recved = 0; npauses = 0; -function onLoad () { - var paused = false; - client = node.tcp.createConnection(PORT); - client.setEncoding("ascii"); - client.addListener("receive", function (d) { - chars_recved += d.length; - puts("got " + chars_recved); - if (!paused) { - client.readPause(); - npauses += 1; - paused = true; - puts("pause"); - x = chars_recved; - setTimeout(function () { - assertEquals(chars_recved, x); - client.readResume(); - puts("resume"); - paused = false; - }, 100); - } - }); +var paused = false; +client = node.tcp.createConnection(PORT); +client.setEncoding("ascii"); +client.addListener("receive", function (d) { + chars_recved += d.length; + puts("got " + chars_recved); + if (!paused) { + client.readPause(); + npauses += 1; + paused = true; + puts("pause"); + x = chars_recved; + setTimeout(function () { + assertEquals(chars_recved, x); + client.readResume(); + puts("resume"); + paused = false; + }, 100); + } +}); - client.addListener("eof", function () { - server.close(); - client.close(); - }); -} +client.addListener("eof", function () { + server.close(); + client.close(); +}); function onExit () { assertEquals(N, chars_recved); diff --git a/test/mjsunit/test-tcp-throttle.js b/test/mjsunit/test-tcp-throttle.js index 0480b7115c..22853d8bf3 100644 --- a/test/mjsunit/test-tcp-throttle.js +++ b/test/mjsunit/test-tcp-throttle.js @@ -21,35 +21,32 @@ server.listen(PORT); recv = ""; chars_recved = 0; -function onLoad () { - client = node.tcp.createConnection(PORT); - client.setEncoding("ascii"); - client.addListener("receive", function (d) { - print(d); - recv += d; - }); +client = node.tcp.createConnection(PORT); +client.setEncoding("ascii"); +client.addListener("receive", function (d) { + print(d); + recv += d; +}); +setTimeout(function () { + chars_recved = recv.length; + puts("pause at: " + chars_recved); + assertTrue(chars_recved > 1); + client.readPause(); setTimeout(function () { - chars_recved = recv.length; - puts("pause at: " + chars_recved); - assertTrue(chars_recved > 1); - client.readPause(); + puts("resume at: " + chars_recved); + assertEquals(chars_recved, recv.length); + client.readResume(); + setTimeout(function () { - puts("resume at: " + chars_recved); - assertEquals(chars_recved, recv.length); - client.readResume(); + chars_recved = recv.length; + puts("pause at: " + chars_recved); + client.readPause(); setTimeout(function () { - chars_recved = recv.length; - puts("pause at: " + chars_recved); - client.readPause(); - - setTimeout(function () { - puts("resume at: " + chars_recved); - assertEquals(chars_recved, recv.length); - client.readResume(); - - }, 500); + puts("resume at: " + chars_recved); + assertEquals(chars_recved, recv.length); + client.readResume(); }, 500); @@ -57,11 +54,12 @@ function onLoad () { }, 500); - client.addListener("eof", function () { - server.close(); - client.close(); - }); -} +}, 500); + +client.addListener("eof", function () { + server.close(); + client.close(); +}); function onExit () { assertEquals(N, recv.length); diff --git a/test/mjsunit/test-timers.js b/test/mjsunit/test-timers.js index 7ae3e2ec21..6b2737467a 100644 --- a/test/mjsunit/test-timers.js +++ b/test/mjsunit/test-timers.js @@ -5,37 +5,35 @@ var WINDOW = 800; // why is does this need to be so big? var interval_count = 0; var setTimeout_called = false; -function onLoad () { - assertInstanceof(setTimeout, Function); - var starttime = new Date; - - setTimeout(function () { - var endtime = new Date; - var diff = endtime - starttime; - if (diff < 0) diff = -diff; - assertTrue(1000 - WINDOW < diff && diff < 1000 + WINDOW); - setTimeout_called = true; - }, 1000); - - // this timer shouldn't execute - var id = setTimeout(function () { assertTrue(false); }, 500); - clearTimeout(id); - - setInterval(function () { - interval_count += 1; - var endtime = new Date; - var diff = endtime - starttime; - if (diff < 0) diff = -diff; - - var t = interval_count * 1000; - - assertTrue(t - WINDOW < diff && diff < t + WINDOW); - - assertTrue(interval_count <= 3); - if (interval_count == 3) - clearInterval(this); - }, 1000); -} +assertInstanceof(setTimeout, Function); +var starttime = new Date; + +setTimeout(function () { + var endtime = new Date; + var diff = endtime - starttime; + if (diff < 0) diff = -diff; + assertTrue(1000 - WINDOW < diff && diff < 1000 + WINDOW); + setTimeout_called = true; +}, 1000); + +// this timer shouldn't execute +var id = setTimeout(function () { assertTrue(false); }, 500); +clearTimeout(id); + +setInterval(function () { + interval_count += 1; + var endtime = new Date; + var diff = endtime - starttime; + if (diff < 0) diff = -diff; + + var t = interval_count * 1000; + + assertTrue(t - WINDOW < diff && diff < t + WINDOW); + + assertTrue(interval_count <= 3); + if (interval_count == 3) + clearInterval(this); +}, 1000); function onExit () { assertTrue(setTimeout_called); diff --git a/test/mjsunit/test-utf8-scripts.js b/test/mjsunit/test-utf8-scripts.js index 0d82e56a8a..01287d1be0 100644 --- a/test/mjsunit/test-utf8-scripts.js +++ b/test/mjsunit/test-utf8-scripts.js @@ -4,7 +4,5 @@ include("mjsunit.js"); puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη"); -function onLoad () { -  assertTrue( /Hellö Wörld/.test("Hellö Wörld") ); -} +assertTrue( /Hellö Wörld/.test("Hellö Wörld") );