<commit_before>
/*!
 * socket.io-node
 * Copyright(c) 2011 LearnBoost <<EMAIL>>
 * MIT Licensed
 */

/**
 * Test dependencies.
 */

var sio = require('socket.io')
  , should = require('./common')
  , parser = sio.parser
  , ports = 15200;

/**
 * Test.
 */

module.exports = {

  'test handshake': function (done) {
    var port = ++ports
      , io = sio.listen(port);

    io.configure(function () {
      io.set('close timeout', .2);
      io.set('polling duration', .2);
    });

    function finish () {
      req.res.socket.end();
      io.server.close();
      done();
    };

    var req = get('/socket.io/{protocol}/', port, function (res, data) {
      var sid = data.split(':')[0]
        , total = 2;

      get('/socket.io/{protocol}/xhr-polling/tobi', port, function (res, packets) {
        res.statusCode.should.eql(200);

        packets.should.have.length(1);
        packets[0].should.eql({
            type: 'error'
          , reason: 'client not handshaken'
          , endpoint: ''
          , advice: ''
        });

        --total || finish();
      });

      // we rely on a small poll duration to close this request quickly
      get('/socket.io/{protocol}/xhr-polling/' + sid, port, function (res, data) {
        res.statusCode.should.eql(200);
        data.should.eql('');
        --total || finish();
      });
    });
  },

  'test the connection event': function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , sid, req;

    io.configure(function () {
      io.set('close timeout', .2);
    });

    io.sockets.on('connection', function (socket) {
      socket.id.should.eql(sid);
      io.server.close();
      done();
    });

    handshake(port, function (sessid) {
      sid = sessid;
      req = get('/socket.io/{protocol}/xhr-polling/' + sid, port);
    });
  },

  'test the disconnection event after a close timeout': function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , sid;

    io.configure(function () {
      io.set('close timeout', .2);
    });

    io.sockets.on('connection', function (socket) {
      socket.id.should.eql(sid);

      socket.on('disconnect', function () {
        io.server.close();
        done();
      });
    });

    handshake(port, function (sessid) {
      sid = sessid;
      var req = get('/socket.io/{protocol}/xhr-polling/' + sid, port);

      // here we close the request instead of relying on a small poll timeout
      setTimeout(function () {
        req.abort();
      }, 50);
    });
  },

  'test the disconnection event when the client sends ?disconnect req':
  function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , disconnected = false
      , sid;

    io.configure(function () {
      io.set('close timeout', .2);
    });

    io.sockets.on('connection', function (socket) {
      get('/socket.io/{protocol}/xhr-polling/' + sid + '/?disconnect', port);

      socket.on('disconnect', function () {
        disconnected = true;
      });
    });

    handshake(port, function (sessid) {
      sid = sessid;
      get('/socket.io/{protocol}/xhr-polling/' + sid, port, function (res, msgs) {
        msgs.should.have.length(1);
        msgs[0].should.eql({ type: 'disconnect', endpoint: '' });
        disconnected.should.be.true;
        io.server.close();
        done();
      });
    });
  },

  'test the disconnection event booting a client': function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , forced = false;

    io.sockets.on('connection', function (socket) {
      socket.on('disconnect', function () {
        io.server.close();
        done();
      });

      socket.disconnect();
      forced = true;
    });

    handshake(port, function (sid) {
      get('/socket.io/{protocol}/xhr-polling/' + sid, port, function (res, msgs) {
        msgs.should.have.length(1);
        msgs[0].should.eql({ type: 'disconnect', endpoint: '' });

        forced.should.be.true;
      });
    });
  },

  'test the disconnection event with client disconnect packet': function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , sid;

    io.sockets.on('connection', function (client) {
      post(
          '/socket.io/{protocol}/xhr-polling/' + sid
        , port
        , parser.encodePacket({ type: 'disconnect' })
        , function (res, data) {
            res.statusCode.should.eql(200);
            data.should.eql('');
            io.server.close();
            done();
          }
      );

      client.on('disonnect', function () {
        done();<commit_msg>Fixed client packet disconnect test.<commit_after>
/*!
 * socket.io-node
 * Copyright(c) 2011 LearnBoost <<EMAIL>>
 * MIT Licensed
 */

/**
 * Test dependencies.
 */

var sio = require('socket.io')
  , should = require('./common')
  , parser = sio.parser
  , ports = 15200;

/**
 * Test.
 */

module.exports = {

  'test handshake': function (done) {
    var port = ++ports
      , io = sio.listen(port);

    io.configure(function () {
      io.set('close timeout', .2);
      io.set('polling duration', .2);
    });

    function finish () {
      req.res.socket.end();
      io.server.close();
      done();
    };

    var req = get('/socket.io/{protocol}/', port, function (res, data) {
      var sid = data.split(':')[0]
        , total = 2;

      get('/socket.io/{protocol}/xhr-polling/tobi', port, function (res, packets) {
        res.statusCode.should.eql(200);

        packets.should.have.length(1);
        packets[0].should.eql({
            type: 'error'
          , reason: 'client not handshaken'
          , endpoint: ''
          , advice: ''
        });

        --total || finish();
      });

      // we rely on a small poll duration to close this request quickly
      get('/socket.io/{protocol}/xhr-polling/' + sid, port, function (res, data) {
        res.statusCode.should.eql(200);
        data.should.eql('');
        --total || finish();
      });
    });
  },

  'test the connection event': function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , sid, req;

    io.configure(function () {
      io.set('close timeout', .2);
    });

    io.sockets.on('connection', function (socket) {
      socket.id.should.eql(sid);
      io.server.close();
      done();
    });

    handshake(port, function (sessid) {
      sid = sessid;
      req = get('/socket.io/{protocol}/xhr-polling/' + sid, port);
    });
  },

  'test the disconnection event after a close timeout': function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , sid;

    io.configure(function () {
      io.set('close timeout', .2);
    });

    io.sockets.on('connection', function (socket) {
      socket.id.should.eql(sid);

      socket.on('disconnect', function () {
        io.server.close();
        done();
      });
    });

    handshake(port, function (sessid) {
      sid = sessid;
      var req = get('/socket.io/{protocol}/xhr-polling/' + sid, port);

      // here we close the request instead of relying on a small poll timeout
      setTimeout(function () {
        req.abort();
      }, 50);
    });
  },

  'test the disconnection event when the client sends ?disconnect req':
  function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , disconnected = false
      , sid;

    io.configure(function () {
      io.set('close timeout', .2);
    });

    io.sockets.on('connection', function (socket) {
      get('/socket.io/{protocol}/xhr-polling/' + sid + '/?disconnect', port);

      socket.on('disconnect', function () {
        disconnected = true;
      });
    });

    handshake(port, function (sessid) {
      sid = sessid;
      get('/socket.io/{protocol}/xhr-polling/' + sid, port, function (res, msgs) {
        msgs.should.have.length(1);
        msgs[0].should.eql({ type: 'disconnect', endpoint: '' });
        disconnected.should.be.true;
        io.server.close();
        done();
      });
    });
  },

  'test the disconnection event booting a client': function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , forced = false;

    io.sockets.on('connection', function (socket) {
      socket.on('disconnect', function () {
        io.server.close();
        done();
      });

      socket.disconnect();
      forced = true;
    });

    handshake(port, function (sid) {
      get('/socket.io/{protocol}/xhr-polling/' + sid, port, function (res, msgs) {
        msgs.should.have.length(1);
        msgs[0].should.eql({ type: 'disconnect', endpoint: '' });

        forced.should.be.true;
      });
    });
  },

  'test the disconnection event with client disconnect packet': function (done) {
    var port = ++ports
      , io = sio.listen(port)
      , sid;

    io.sockets.on('connection', function (client) {
      post(
          '/socket.io/{protocol}/xhr-polling/' + sid
        , port
        , parser.encodePacket({ type: 'disconnect' })
        , function (res, data) {
            res.statusCode.should.eql(200);
            data.should.eql('');
          }
      );

      client.on('disconnect', function () {
        io.server.close();
        done();
{'fraction_non_alphanumeric': 0.17354289456450556, 'fraction_numerical': 0.007203667321545514, 'mean_word_length': 2.0758643840214837, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3611786', 'n_tokens_mistral': 2969, 'n_tokens_neox': 2868, 'n_words': 624}