Skip to content

Commit 074e74c

Browse files
committed
Added test for emitting to closed clients to prevent regression.
1 parent 65b8272 commit 074e74c

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

test/transports.xhr-polling.test.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,4 +2635,82 @@ module.exports = {
26352635
});
26362636
},
26372637

2638+
'test emitting to closed clients': function (done) {
2639+
var cl = client(++ports)
2640+
, cl2 = client(ports)
2641+
, io = create(cl)
2642+
, connections = 0;
2643+
2644+
io.configure(function () {
2645+
io.set('close timeout', .1);
2646+
});
2647+
2648+
io.sockets.on('connection', function (socket) {
2649+
socket.send('a');
2650+
});
2651+
2652+
cl.handshake(function (sid) {
2653+
cl.get('/socket.io/{protocol}/xhr-polling/' + sid, function (res, packs) {
2654+
res.statusCode.should.equal(200);
2655+
packs.should.have.length(1);
2656+
packs[0].should.eql({ type: 'message', endpoint: '', data: 'a' });
2657+
2658+
cl2.handshake(function (sid2) {
2659+
cl2.get(
2660+
'/socket.io/{protocol}/xhr-polling/' + sid2
2661+
, function (res, packs) {
2662+
res.statusCode.should.equal(200);
2663+
packs.should.have.length(1);
2664+
packs[0].should.eql({ type: 'message', endpoint: '', data: 'a' });
2665+
2666+
io.sockets.emit('woot', 'b');
2667+
2668+
var total = 2;
2669+
2670+
cl.get(
2671+
'/socket.io/{protocol}/xhr-polling/' + sid
2672+
, function (res, packs) {
2673+
res.statusCode.should.equal(200);
2674+
packs.should.have.length(1);
2675+
packs[0].should.eql({
2676+
type: 'event'
2677+
, endpoint: ''
2678+
, name: 'woot'
2679+
, args: ['b']
2680+
});
2681+
2682+
--total || finish();
2683+
}
2684+
);
2685+
2686+
cl2.get(
2687+
'/socket.io/{protocol}/xhr-polling/' + sid2
2688+
, function (res, packs) {
2689+
res.statusCode.should.equal(200);
2690+
packs.should.have.length(1);
2691+
packs[0].should.eql({
2692+
type: 'event'
2693+
, endpoint: ''
2694+
, name: 'woot'
2695+
, args: ['b']
2696+
});
2697+
2698+
--total || finish();
2699+
}
2700+
);
2701+
2702+
function finish () {
2703+
cl.end();
2704+
cl2.end();
2705+
io.server.close();
2706+
done();
2707+
};
2708+
}
2709+
);
2710+
});
2711+
2712+
});
2713+
});
2714+
}
2715+
26382716
};

0 commit comments

Comments
 (0)