Permalink
Browse files

websocket, break: delete nouse test case.

  • Loading branch information...
xicilion committed Oct 20, 2017
1 parent c39d703 commit 4fe56e695ab5f7fbce102f6005ad426312d345fc
Showing with 1 addition and 249 deletions.
  1. +1 −249 test/ws_test.js
View
@@ -18,7 +18,7 @@ describe('ws', () => {
});
});
xdescribe('Message', () => {
describe('Message', () => {
function load_msg(data) {
var ms = new io.MemoryStream();
ms.write(data);
@@ -138,254 +138,6 @@ describe('ws', () => {
test_msg(65536);
test_msg(65536, true);
});
it("handshake", () => {
function test_msg(n, masked) {
var msg = new ws.Message();
msg.type = ws.TEXT;
msg.masked = masked;
var buf = new Buffer(n);
for (var i = 0; i < n; i++) {
buf[i] = (i % 10) + 0x30;
}
msg.body.write(buf);
msg.sendTo(rep.stream);
var msg = new ws.Message();
msg.readFrom(rep.stream);
assert.equal(msg.body.readAll().toString(), buf.toString());
}
var httpd = new http.Server(8810 + base_port, new ws.Handler((v) => {
v.response.body = v.body;
}));
ss.push(httpd.socket);
httpd.run(() => {});
var rep = http.get("http://127.0.0.1:" + (8810 + base_port) + "/", {
headers: {
"Upgrade": "websocket",
"Connection": "Upgrade",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
"Sec-WebSocket-Version": "13"
}
});
assert.equal(rep.firstHeader("Sec-WebSocket-Accept"), "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
assert.equal(rep.firstHeader("Upgrade"), "websocket");
assert.equal(rep.statusCode, 101);
assert.equal(rep.upgrade, true);
test_msg(10, true);
test_msg(100, true);
test_msg(125, true);
test_msg(126, true);
test_msg(65535, true);
test_msg(65536, true);
rep.stream.stream.close();
var rep = http.get("http://127.0.0.1:" + (8810 + base_port) + "/", {
"Connection": "Upgrade",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
"Sec-WebSocket-Version": "13"
});
assert.equal(rep.statusCode, 500);
rep.stream.stream.close();
var rep = http.get("http://127.0.0.1:" + (8810 + base_port) + "/", {
"Upgrade": "websocket",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
"Sec-WebSocket-Version": "13"
});
assert.equal(rep.statusCode, 500);
rep.stream.stream.close();
var rep = http.get("http://127.0.0.1:" + (8810 + base_port) + "/", {
"Upgrade": "websocket",
"Connection": "Upgrade",
"Sec-WebSocket-Version": "13"
});
assert.equal(rep.statusCode, 500);
rep.stream.stream.close();
var rep = http.get("http://127.0.0.1:" + (8810 + base_port) + "/", {
"Upgrade": "websocket",
"Connection": "Upgrade",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ=="
});
assert.equal(rep.statusCode, 500);
assert.throws(() => {
test_msg(10);
});
rep.stream.stream.close();
});
it("connect", () => {
function test_msg(n, masked) {
var msg = new ws.Message();
msg.type = ws.TEXT;
msg.masked = masked;
var buf = new Buffer(n);
for (var i = 0; i < n; i++) {
buf[i] = (i % 10) + 0x30;
}
msg.body.write(buf);
msg.sendTo(s);
var msg = new ws.Message();
msg.readFrom(s);
assert.equal(msg.body.readAll().toString(), buf.toString());
}
var s = ws.connect("ws://127.0.0.1:" + (8810 + base_port) + "/");
test_msg(10, true);
test_msg(100, true);
test_msg(125, true);
test_msg(126, true);
test_msg(65535, true);
test_msg(65536, true);
s.close();
});
it("ping", () => {
var s = ws.connect("ws://127.0.0.1:" + (8810 + base_port) + "/");
var body = "hello";
var msg = new ws.Message();
msg.type = ws.PING;
msg.body.write(body);
msg.sendTo(s);
var msg = new ws.Message();
msg.readFrom(s);
assert.equal(msg.type, ws.PONG);
assert.equal(msg.body.readAll().toString(), body);
s.close();
});
it("close", () => {
var s = ws.connect("ws://127.0.0.1:" + (8810 + base_port) + "/");
var msg = new ws.Message();
msg.type = ws.CLOSE;
msg.sendTo(s);
var msg = new ws.Message();
assert.throws(() => {
msg.readFrom(s);
});
s.close();
});
it("non-control opcode", () => {
var s = ws.connect("ws://127.0.0.1:" + (8810 + base_port) + "/");
var msg = new ws.Message();
msg.type = 5;
msg.sendTo(s);
var msg = new ws.Message();
assert.throws(() => {
msg.readFrom(s);
});
s.close();
});
it("drop other type message", () => {
var s = ws.connect("ws://127.0.0.1:" + (8810 + base_port) + "/");
var msg = new ws.Message();
msg.type = ws.PONG;
msg.sendTo(s);
var msg = new ws.Message();
assert.throws(() => {
msg.readFrom(s);
});
s.close();
});
it("remote close", () => {
var httpd = new http.Server(8811 + base_port, new ws.Handler((v) => {
v.stream.close();
}));
ss.push(httpd.socket);
httpd.run(() => {});
var s = ws.connect("ws://127.0.0.1:" + (8811 + base_port) + "/");
var msg = new ws.Message();
msg.type = ws.TEXT;
msg.sendTo(s);
var msg = new ws.Message();
assert.throws(() => {
msg.readFrom(s);
});
s.close();
});
it("onerror", () => {
var err_500 = 0;
var hdlr = new ws.Handler((v) => {
throw new Error("test error");
});
hdlr.onerror({
500: (v) => {
err_500++;
console.error(v.lastError);
}
});
var httpd = new http.Server(8812 + base_port, hdlr);
ss.push(httpd.socket);
httpd.run(() => {});
var s = ws.connect("ws://127.0.0.1:" + (8812 + base_port) + "/");
var msg = new ws.Message();
msg.type = ws.TEXT;
msg.sendTo(s);
for (var i = 0; i < 100 && err_500 == 0; i++)
coroutine.sleep(1);
assert.equal(err_500, 1);
s.close();
});
});
describe('WebSocketHandler', () => {

0 comments on commit 4fe56e6

Please sign in to comment.