<commit_before>var assert = require('assert');
require('../common.js');

suite('Latency - Error', function() {
  test('insert', function(done, server, client) {
    server.evalSync(doAutoPublish);
    server.evalSync(function() {
      coll = new Meteor.SmartCollection('coll');
      coll.allow({
        insert: function() {return true}
      })
      emit('return');
    });

    var received = [];
    var error;
    client.on('added', function(doc) {
      received.push(['a', doc])
    });

    client.on('removed', function(doc) {
      received.push(['r', doc]);
    });

    client.on('error', function(err) {
      error = err;
    });

    client.eval(function() {
      coll = new Meteor.SmartCollection('coll');
      coll.find().observe({ 
        added: function(doc) {
          emit('added', doc);
        },
        removed: function(doc) {
          emit('removed', doc);
        }
      });

      //we use $aa to make an error from node mogno driver
      coll.insert({_id: 'aa', $aa: 10}, function(err) {
        emit('error', err);
      });
    });

    setTimeout(function() {
      assert.ok(error);
      assert.deepEqual(received, [
        ['a', {_id: 'aa', $aa: 10}],
        ['r', {_id: 'aa', $aa: 10}]
      ]);
      done();
    }, 400);
  });

  // //I couldn't able to find a reliable to make some error on update, so this test left blank
  // test('update', function(done, server, client) {
  //   server.evalSync(doAutoPublish);
  //   server.evalSync(function() {
  //     coll = new Meteor.SmartCollection('coll');
  //     coll.insert({_id: 'aa', aa: "coola"});
  //     coll._ensureIndex({aa: true});
<commit_msg>optimized tests<commit_after>var assert = require('assert');
require('../common.js');

suite('Latency - Error', function() {
  test('insert', function(done, server, client) {
    server.evalSync(doAutoPublish);
    server.evalSync(function() {
      coll = new Meteor.SmartCollection('coll');
      coll.allow({
        insert: function() {return true}
      })
      emit('return');
    });

    var received = [];
    client.on('added', function(doc) {
      received.push(['a', doc])
    });

    client.on('removed', function(doc) {
      received.push(['r', doc]);
    });

    client.on('error', function(error) {
      assert.ok(error);
      assert.deepEqual(received, [
        ['a', {_id: 'aa', $aa: 10}],
        ['r', {_id: 'aa', $aa: 10}]
      ]);
      done();
    });

    client.eval(function() {
      coll = new Meteor.SmartCollection('coll');
      coll.find().observe({ 
        added: function(doc) {
          emit('added', doc);
        },
        removed: function(doc) {
          emit('removed', doc);
        }
      });

      //we use $aa to make an error from node mogno driver
      coll.insert({_id: 'aa', $aa: 10}, function(err) {
        emit('error', err);
      });
    });
  });

  // //I couldn't able to find a reliable to make some error on update, so this test left blank
  // test('update', function(done, server, client) {
  //   server.evalSync(doAutoPublish);
  //   server.evalSync(function() {
  //     coll = new Meteor.SmartCollection('coll');
  //     coll.insert({_id: 'aa', aa: "coola"});
  //     coll._ensureIndex({aa: true});

{'fraction_non_alphanumeric': 0.19066749072929542, 'fraction_numerical': 0.0046353522867737945, 'mean_word_length': 2.3789144050104385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7363471', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1016, 'n_words': 229}