Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Test binary websocket bouncing, on top of RFC-6455 #21

Open
wants to merge 3 commits into from

1 participant

@einaros

The pre-existing websocket tests deal with the old hixie drafts. The hybi drafts, which eventually became rfc-6455, are somewhat different. Testing for compatibility with both protocol families, and also well-behaved echo of a large binary blob (5MB), seems practical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 16, 2012
  1. @einaros

    added websocket binary tests

    einaros authored
Commits on Jan 17, 2012
  1. @einaros
  2. @einaros

    typo

    einaros authored
This page is out of date. Refresh to see the latest.
Showing with 57 additions and 1 deletion.
  1. +3 −1 package.json
  2. +54 −0 test/ws_binary.js
View
4 package.json
@@ -38,7 +38,9 @@
"lazy" : "1.0.x",
"websocket-server" : "1.4.x",
"wsclient" : "0.2.x",
- "chunky" : "0.0.x"
+ "chunky" : "0.0.x",
+ "ws": "0.4.x",
+ "buffertools": "1.0.x"
},
"engines" : {
"node" : ">=0.4.0"
View
54 test/ws_binary.js
@@ -0,0 +1,54 @@
+var test = require('tap').test;
+var bouncy = require('../');
+var ws = require('ws').Server;
+var wc = require('ws');
+require('buffertools');
+
+test('ws_binary', function (t) {
+ t.plan(2);
+
+ var randomBuf = new Buffer(5*1024*1024);
+ for (var i = 0, l = randomBuf.length; i < l; ++i) {
+ randomBuf[i] = ~~(Math.random() * 255);
+ }
+
+ var p0 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
+ var s0 = new ws({port: p0}, connect);
+ s0.on('connection', function (c) {
+ c.on('message', function (buf) {
+ t.equal(0, buf.compare(randomBuf));
+ c.send(buf, {binary: true});
+ c.close();
+ });
+ c.on('error', function (error) {
+ throw error;
+ });
+ });
+
+ var p1 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
+ var s1 = bouncy(function (req, bounce) {
+ bounce(p0);
+ });
+ s1.listen(p1, connect);
+
+ var connected = 0;
+ function connect () {
+ if (++connected !== 2) return;
+
+ var c = new wc('ws://localhost:' + p1 + '/');
+
+ c.on('open', function () {
+ c.send(randomBuf, {binary: true});
+ });
+
+ c.on('close', function () {
+ s0.close();
+ s1.close();
+ t.end();
+ });
+
+ c.on('message', function (buf) {
+ t.equal(0, buf.compare(randomBuf));
+ });
+ }
+});
Something went wrong with that request. Please try again.