<|start_filename|>test/helpers/queryEx.js<|end_filename|>

var Future = Npm.require('fibers/future');

// Must be bound to node-mysql connection instance
queryEx = function(query){
  var self = this;
  var fut = new Future();
  if(typeof query === 'function'){
    var escId = self.escapeId;
    var esc = self.escape.bind(self);
    query = query(esc, escId);
  }
  self.query(query, Meteor.bindEnvironment(function(error, rows, fields){
    if(error) return fut['throw'](error);
    fut['return'](rows);
  }));
  return fut.wait();
}


<|start_filename|>test/benchmark/insertMany.js<|end_filename|>
// numtel:mysql
// MIT License, <EMAIL>
// test/benchmark/insertMany.js

// Benchmark number of inserts published to client per second
// Compare MySQL binlog, Mongo, and Mongo-Direct
var genMysqlTest = function(){
  var subscription = new MysqlSubscription('benchmark_players');
  return {
    run: function(options, done){
      var startCount = subscription.length;
      subscription.addEventListener('added.insertRows', function(){
        var result;
        if(subscription.length === startCount + options.count){
          subscription.removeEventListener(/insertRows/);
          done();
        }
      });
      Meteor.call('benchmark_insert', options.count, function(error){
        if(error && error.error === 404){
          subscription.removeEventListener(/insertRows/);
          done();
        }
        done('server');
      });
    },
    reset: function(options, done){
      if(subscription.length === 0) return done();
      Meteor.call('benchmark_reset');
      subscription.addEventListener('removed.resetTable', function(){
        if(subscription.length === 0){
          subscription.removeEventListener(/resetTable/);
          done();
        }
      });
    }
  }
};

// Both Mongo tests use same collection
MongoPlayers = new Mongo.Collection('MongoPlayers');
var genMongoTest = function(meteorMethod){
  return {
    run: function(options, done){
      var cursor = MongoPlayers.find();
      var startCount = cursor.count();
      var observer = cursor.observe({
        added: function(){
          if(cursor.count() === startCount + options.count){
            observer.stop();
            done();
          }
        }
      });
      Meteor.call(meteorMethod, options.count, function(){ done('server'); });
    },
    reset: function(options, done){
      var cursor = MongoPlayers.find();
      if(cursor.count() === 0) return done();
      var observer = cursor.observe({
        removed: function(){
          if(cursor.count() === 0){
            observer.stop();
            done();
          }
        }
      });
      Meteor.call('resetCollection');
    }
  };
};

Benchmark.addCase({
  _label: 'Insert Rows',
  _value: 'rate',
  _default: {
    count: 1000,
    sampleSize: 1,
    // Explictly specify methods for easy omission
    methods: ['mysql-binlog', 'mongo-standard', 'mongo-direct']
  },
  'mysql-binlog': genMysqlTest(),
  'mongo-standard': genMongoTest('insDocs'),
  'mongo-direct': genMongoTest('insDocsDirect')
});


<|start_filename|>test/simple_rest.js<|end_filename|>
// numtel:mysql
// MIT License, <EMAIL>
// test/simple_rest.js

var SUITE_PREFIX = 'numtel:mysql - simple:rest support - ';

Tinytest.addAsync(SUITE_PREFIX + 'allPlayers publication', function(test, done){
  HTTP.get(Meteor.absoluteUrl() + '/publications/allPlayers',
    function(error, result) {
      test.equal(result.statusCode, 200);

      // JSON data does not come ordered
      var data = _.sortBy(result.data.data, '_index');

      // expectedRows is defined in test/MysqlSubscription.js
      test.equal(expectResult(data, expectedRows), true);
      done();
    }
  );
});
