Browse Source

improved ping pong test.

v0.7.4-release
Ryan 16 years ago
parent
commit
8514e0627a
  1. 13
      test/test-pingpong.js

13
test/test-pingpong.js

@ -1,17 +1,18 @@
include("mjsunit"); include("mjsunit");
var N = 1000;
function onLoad() { function onLoad() {
server = new Server(1024); server = new Server(1024);
var count = 0; var count = 0;
server.listenTCP(12123, function (connection) { server.listenTCP(12123, function (connection) {
puts("got connection."); puts("got connection.");
connection.onRead = function (data) { connection.onRead = function (data) {
assertTrue(count <= 10); assertTrue(count <= N);
if (data === null) { if (data === null) {
server.close(); server.close();
connection.close(); connection.close();
return; return;
} }
stdout.write ("-"); //stdout.write ("-");
if (/QUIT/.exec(data)) { if (/QUIT/.exec(data)) {
server.close(); server.close();
connection.close(); connection.close();
@ -23,23 +24,23 @@ function onLoad() {
socket = new Socket; socket = new Socket;
socket.onRead = function (data) { socket.onRead = function (data) {
stdout.write ("."); //stdout.write(".");
assertEquals("PONG", data); assertEquals("PONG", data);
setTimeout(function() { setTimeout(function() {
count += 1; count += 1;
if (count < 10) { if (count < N) {
socket.write("PING"); socket.write("PING");
} else { } else {
stdout.write ("\n"); stdout.write ("\n");
socket.write("QUIT\n"); socket.write("QUIT\n");
socket.close(); socket.close();
} }
}, 100); }, 10);
}; };
socket.onClose = function () { socket.onClose = function () {
puts("socket close."); puts("socket close.");
assertEquals(10, count); assertEquals(N, count);
}; };
socket.connectTCP(12123, "localhost", function (status) { socket.connectTCP(12123, "localhost", function (status) {

Loading…
Cancel
Save