summaryrefslogtreecommitdiff
path: root/node_modules/socket.io/support/node-websocket-client/test/test-client-close.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
committerJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
commit686106d544ecc3b6ffd4db2b665d3bc879a58d8c (patch)
treea5b5e50237cef70e12f0745371896e96f5f6d578 /node_modules/socket.io/support/node-websocket-client/test/test-client-close.js
ok
Diffstat (limited to 'node_modules/socket.io/support/node-websocket-client/test/test-client-close.js')
-rw-r--r--node_modules/socket.io/support/node-websocket-client/test/test-client-close.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/node_modules/socket.io/support/node-websocket-client/test/test-client-close.js b/node_modules/socket.io/support/node-websocket-client/test/test-client-close.js
new file mode 100644
index 0000000..76fb81f
--- /dev/null
+++ b/node_modules/socket.io/support/node-websocket-client/test/test-client-close.js
@@ -0,0 +1,43 @@
+// Verify that a connection can be closed gracefully from the client.
+
+var assert = require('assert');
+var WebSocket = require('../lib/websocket').WebSocket;
+var WebSocketServer = require('websocket-server/ws/server').Server;
+
+var PORT = 1024 + Math.floor(Math.random() * 4096);
+var C_MSG = 'Client test: ' + (Math.random() * 100);
+
+var serverGotClientMessage = false;
+var clientGotServerClose = false;
+var serverGotClientClose = false;
+
+var wss = new WebSocketServer();
+wss.listen(PORT, 'localhost');
+wss.on('connection', function(c) {
+ c.on('message', function(m) {
+ assert.equal(m, C_MSG);
+ serverGotClientMessage = true;
+ });
+ c.on('close', function() {
+ serverGotClientClose = true;
+ wss.close();
+ });
+});
+
+var ws = new WebSocket('ws://localhost:' + PORT);
+ws.onopen = function() {
+ ws.send(C_MSG);
+
+ // XXX: Add a timeout here
+ ws.close(5);
+};
+ws.onclose = function() {
+ assert.equal(ws.CLOSED, ws.readyState);
+ clientGotServerClose = true;
+};
+
+process.on('exit', function() {
+ assert.ok(serverGotClientMessage);
+ assert.ok(clientGotServerClose);
+ assert.ok(serverGotClientClose);
+});