Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added websocket binary tests

  • Loading branch information...
commit 286e2144589dc716a20bc56f1ebf40a2696d24ac 1 parent 3f13cd4
@einaros einaros authored
Showing with 56 additions and 1 deletion.
  1. +3 −1 package.json
  2. +53 −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
53 test/ws_binary.js
@@ -0,0 +1,53 @@
+var test = require('tap').test;
+var bouncy = require('../');
+var ws = require('ws').Server;
+var wc = require('ws');
+var crypto = require('crypto');
+require('buffertools');
+
+test('ws_binary', function (t) {
+ t.plan(2);
+ crypto.randomBytes(5*1024*1024, function(ex, randomBuf) {
+ if (ex) throw ex;
+
+ 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 (msg) {
+ t.equal(0, msg.compare(randomBuf));
+ c.send(msg, {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));
+ });
+ }
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.