<commit_before>describe('f2-client-disconnection', function () {

  this.timeout(120000);

  require('benchmarket').start();
  after(require('benchmarket').store());

  var expect = require('expect.js');

  var Mesh = require('../');
  var mesh;

  var adminClient = new Mesh.MeshClient({secure: true, port: 8884,
    reconnect:{
      max:2000 //we can then wait 10 seconds and should be able to reconnect before the next 10 seconds,
    }
  });

  var test_id = Date.now() + '_' + require('shortid').generate();

  var startMesh = function(middleware, callback){

    Mesh.create({
      name: 'f2-client-disconnection',
      datalayer: {
        secure: true,
        adminPassword: <PASSWORD>,
        port: 8884,
        transformMiddleware:middleware
      },
      components: {
        'data': {}
      }
    }, function(e, instance){

      if (e) return callback(e);
      mesh = instance;
      callback();

    });
  };

  before(function (done) {
    done();
  });

  after(function (done) {
    done();
  });

  it('tests the client disconnection with promise login', function (done) {

    this.timeout(10000);

    var packetsIn = [];
    var packetsOut = [];

    var spyConfig = {

      suppressPrint:true,

      log:function(direction, packet){

        if (direction == 'incoming') packetsIn.push(packet);
        if (direction == 'outgoing') packetsOut.push(packet);

      }
    };

    var middleware = [{path:'./transform-message-spy', options:spyConfig}];

    startMesh(middleware, function(e){
      if (e) return done(e);

      adminClient
        .login({username: '_ADMIN', password: <PASSWORD>})
        .then(finishTest())
        .catch(done);
    });

    var finishTest = function(){

      adminClient.disconnect(function(e){

        if (e) return done(e);
        packetsIn = [];

        setTimeout(function(){

          console.log('packetsIn:::', packetsIn);
          done();

        }, 5000);

      });
    };
  });

  it.only('tests the client disconnection with callback login', function (done) {
    this.timeout(10000);

    var packetsIn = [];
    var packetsOut = [];

    var spyConfig = {

      suppressPrint:true,

      log:function(direction, packet){

        if (direction == 'incoming') packetsIn.push(packet);
        if (direction == 'outgoing') packetsOut.push(packet);

      }
    };

    var middleware = [{path:'./transform-message-spy', options:spyConfig}];<commit_msg>pass finishTest to then instead of calling it<commit_after>describe('f2-client-disconnection', function () {

  this.timeout(120000);

  require('benchmarket').start();
  after(require('benchmarket').store());

  var expect = require('expect.js');

  var Mesh = require('../');
  var mesh;

  var adminClient = new Mesh.MeshClient({secure: true, port: 8884,
    reconnect: {
      max: 2000
    }
  });

  var test_id = Date.now() + '_' + require('shortid').generate();

  var startMesh = function(middleware, callback){

    Mesh.create({
      name: 'f2-client-disconnection',
      datalayer: {
        secure: true,
        adminPassword: <PASSWORD>,
        port: 8884,
        transformMiddleware:middleware
      },
      components: {
        'data': {}
      }
    }, function(e, instance){

      if (e) return callback(e);
      mesh = instance;
      callback();

    });
  };

  before(function (done) {
    done();
  });

  after(function (done) {
    done();
  });

  it('tests the client disconnection with promise login', function (done) {

    this.timeout(10000);

    var packetsIn = [];
    var packetsOut = [];

    var spyConfig = {

      suppressPrint:true,

      log:function(direction, packet){

        if (direction == 'incoming') packetsIn.push(packet);
        if (direction == 'outgoing') packetsOut.push(packet);

      }
    };

    var middleware = [{path:'./transform-message-spy', options:spyConfig}];

    startMesh(middleware, function(e){
      if (e) return done(e);

      adminClient
        .login({username: '_ADMIN', password: <PASSWORD>})
        .then(finishTest)
        .catch(done);
    });

    var finishTest = function(){

      adminClient.disconnect(function(e){

        if (e) return done(e);
        packetsIn = [];

        setTimeout(function(){

          console.log('packetsIn:::', packetsIn);
          done();

        }, 5000);

      });
    };
  });

  it.only('tests the client disconnection with callback login', function (done) {

    this.timeout(10000);

    var packetsIn = [];
    var packetsOut = [];

    var spyConfig = {

      suppressPrint:true,

      log:function(direction, packet){

        if (direction == 'incoming') packetsIn.push(packet);
        if (direction == 'outgoing') packetsOut.push(packet);

      }
    };

    var middleware = [{path:'./transform-message-spy', options:spyConfig}];
{'fraction_non_alphanumeric': 0.15434016987777088, 'fraction_numerical': 0.014916096954630205, 'mean_word_length': 2.5447870778267254, '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': '5030048', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1415, 'n_words': 318}