Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #155 from albertyfwu/bug89

fixed bug89 and added tests: writeBuffer not flushed until nextTick'
  • Loading branch information...
commit 82537a90ccadcdce3baaf55c3d076bc300eecf27 2 parents 5a2ee6c + 300b096
Guillermo Rauch rauchg authored
Showing with 25 additions and 0 deletions.
  1. +6 −0 lib/socket.js
  2. +19 −0 test/server.js
6 lib/socket.js
View
@@ -226,6 +226,12 @@ Socket.prototype.clearTransport = function () {
Socket.prototype.onClose = function (reason, description) {
if ('closed' != this.readyState) {
+ var self = this;
+ // clean writeBuffer in next tick, so developers can still
+ // grab the writeBuffer on 'close' event
+ process.nextTick(function() {
+ self.writeBuffer = [];
+ });
this.packetsFn = [];
this.sentCallbackFn = [];
this.clearTransport();
19 test/server.js
View
@@ -227,6 +227,25 @@ describe('server', function () {
});
describe('close', function () {
+ it('should be able to access non-empty writeBuffer at closing', function(done) {
+ var opts = {allowUpgrades: false, pingInterval: 10, pingTimeout: 10 };
+ var engine = listen(opts, function (port) {
+ var socket = new eioc.Socket('http://localhost:%d'.s(port));
+ socket.sendPacket = function (){};
+ engine.on('connection', function (conn) {
+ conn.on('close', function (reason) {
+ expect(conn.writeBuffer.length).to.be(1);
+ setTimeout(function () {
+ expect(conn.writeBuffer.length).to.be(0); // writeBuffer has been cleared
+ }, 10);
+ done();
+ });
+ conn.writeBuffer.push({ type: 'message', data: 'foo'});
+ conn.onError('');
+ });
+ });
+ });
+
it('should trigger on server if the client does not pong', function (done) {
var opts = { allowUpgrades: false, pingInterval: 5, pingTimeout: 5 };
var engine = listen(opts, function (port) {
Please sign in to comment.
Something went wrong with that request. Please try again.