Skip to content

Commit

Permalink
Merge pull request #1903 from rase-/add/volatile-tests
Browse files Browse the repository at this point in the history
Added tests for volatile
  • Loading branch information
rauchg committed Jan 17, 2015
2 parents 086ccd2 + d9996f0 commit b8ded0d
Showing 1 changed file with 202 additions and 0 deletions.
202 changes: 202 additions & 0 deletions test/socket.io.js
Expand Up @@ -815,6 +815,208 @@ describe('socket.io', function(){
});
});

it('should not emit volatile event after regular event (polling)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['polling'] });

var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
s.emit('ev', 'data');
s.volatile.emit('ev', 'data');
});

var socket = client(srv, { transports: ['polling'] });
socket.on('ev', function() {
counter++;
});
});

setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});

it('should not emit volatile event after regular event (ws)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['websocket'] });

var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
s.emit('ev', 'data');
s.volatile.emit('ev', 'data');
});

var socket = client(srv, { transports: ['websocket'] });
socket.on('ev', function() {
counter++;
});
});

setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});

it('should emit volatile event (polling)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['polling'] });

var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
}, 20);
});

var socket = client(srv, { transports: ['polling'] });
socket.on('ev', function() {
counter++;
});
});

setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});

it('should emit volatile event (ws)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['websocket'] });

var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
}, 20);
});

var socket = client(srv, { transports: ['websocket'] });
socket.on('ev', function() {
counter++;
});
});

setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});

it('should emit only one consecutive volatile event (polling)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['polling'] });

var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
s.volatile.emit('ev', 'data');
}, 20);
});

var socket = client(srv, { transports: ['polling'] });
socket.on('ev', function() {
counter++;
});
});

setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});

it('should emit only one consecutive volatile event (ws)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['websocket'] });

var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.volatile.emit('ev', 'data');
s.volatile.emit('ev', 'data');
}, 20);
});

var socket = client(srv, { transports: ['websocket'] });
socket.on('ev', function() {
counter++;
});
});

setTimeout(function() {
expect(counter).to.be(1);
done();
}, 200);
});

it('should emit regular events after trying a failed volatile event (polling)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['polling'] });

var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.emit('ev', 'data');
s.volatile.emit('ev', 'data');
s.emit('ev', 'data');
}, 20);
});

var socket = client(srv, { transports: ['polling'] });
socket.on('ev', function() {
counter++;
});
});

setTimeout(function() {
expect(counter).to.be(2);
done();
}, 200);
});

it('should emit regular events after trying a failed volatile event (ws)', function(done) {
var srv = http();
var sio = io(srv, { transports: ['websocket'] });

var counter = 0;
srv.listen(function(){
sio.on('connection', function(s){
// Wait to make sure there are no packets being sent for opening the connection
setTimeout(function() {
s.emit('ev', 'data');
s.volatile.emit('ev', 'data');
s.emit('ev', 'data');
}, 20);
});

var socket = client(srv, { transports: ['websocket'] });
socket.on('ev', function() {
counter++;
});
});

setTimeout(function() {
expect(counter).to.be(2);
done();
}, 200);
});

it('should emit message events through `send`', function(done){
var srv = http();
var sio = io(srv);
Expand Down

0 comments on commit b8ded0d

Please sign in to comment.