Add missing semicolons, fix variables scope

- Lines 481 - 498: `val` and `x` is defined twice (hoisting)
 - Lines 973 - 975 and 980 - 982: `expectedRemoves` and `expectedAdds`
is defined on lines 952 and 955
This commit is contained in:
dr-dimitru
2016-12-21 03:20:17 +03:00
parent 1472a41a16
commit 4197c9d99e

View File

@@ -478,22 +478,24 @@ Tinytest.addAsync("mongo-livedata - fuzz test, " + idGeneration, function(test,
var batch_count = rnd(10) + 1;
for (var i = 0; i < batch_count; i++) {
// 25% add, 25% remove, 25% change in place, 25% change and move
var x;
var op = rnd(4);
var which = rnd(correct.length);
if (op === 0 || step < 2 || !correct.length) {
// Add
var x = rnd(1000000);
x = rnd(1000000);
coll.insert({run: run, x: x});
correct.push(x);
max_counters.add++;
} else if (op === 1 || op === 2) {
var x = correct[which];
var val;
x = correct[which];
if (op === 1)
// Small change, not likely to cause a move
var val = x + (rnd(2) ? -1 : 1);
val = x + (rnd(2) ? -1 : 1);
else
// Large change, likely to cause a move
var val = rnd(1000000);
val = rnd(1000000);
coll.update({run: run, x: x}, {$set: {x: val}});
correct[which] = val;
max_counters.change++;
@@ -968,16 +970,16 @@ if (Meteor.isServer) {
// another. Poll-n-diff code, on the other side, analyzes the batch action
// of multiple remove. Because of that difference, expected outputs differ.
if (usesOplog) {
var expectedRemoves = [{removed: docId3}, {removed: docId1},
expectedRemoves = [{removed: docId3}, {removed: docId1},
{removed: docId2}, {removed: docId4}];
var expectedAdds = [{added: docId4}, {added: docId8},
expectedAdds = [{added: docId4}, {added: docId8},
{added: docId7}, {added: docId6}];
test.length(o.output, 8);
} else {
var expectedRemoves = [{removed: docId3}, {removed: docId1},
expectedRemoves = [{removed: docId3}, {removed: docId1},
{removed: docId2}];
var expectedAdds = [{added: docId8}, {added: docId7}, {added: docId6}];
expectedAdds = [{added: docId8}, {added: docId7}, {added: docId6}];
test.length(o.output, 6);
}
@@ -2229,7 +2231,7 @@ function collectionInsert (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'foo');
}));
};
}
function collectionUpsert (test, expect, coll, index) {
var upsertId = '123456' + index;
@@ -2242,7 +2244,7 @@ function collectionUpsert (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'foo');
}));
};
}
function collectionUpsertExisting (test, expect, coll, index) {
var clientSideId = coll.insert({name: "foo"}, expect(function (err1, id) {
@@ -2262,7 +2264,7 @@ function collectionUpsertExisting (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'bar');
}));
};
}
function functionCallsInsert (test, expect, coll, index) {
Meteor.call("insertObjects", coll._name, {name: "foo"}, 1, expect(function (err1, ids) {
@@ -2276,7 +2278,7 @@ function functionCallsInsert (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'foo');
}));
};
}
function functionCallsUpsert (test, expect, coll, index) {
var upsertId = '123456' + index;
@@ -2288,7 +2290,7 @@ function functionCallsUpsert (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'foo');
}));
};
}
function functionCallsUpsertExisting (test, expect, coll, index) {
var id = coll.insert({name: "foo"});
@@ -2305,7 +2307,7 @@ function functionCallsUpsertExisting (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'bar');
}));
};
}
function functionCalls3Inserts (test, expect, coll, index) {
Meteor.call("insertObjects", coll._name, {name: "foo"}, 3, expect(function (err1, ids) {
@@ -2321,7 +2323,7 @@ function functionCalls3Inserts (test, expect, coll, index) {
test.equal(o.name, 'foo');
}
}));
};
}
function functionChainInsert (test, expect, coll, index) {
Meteor.call("doMeteorCall", "insertObjects", coll._name, {name: "foo"}, 1, expect(function (err1, ids) {
@@ -2335,7 +2337,7 @@ function functionChainInsert (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'foo');
}));
};
}
function functionChain2Insert (test, expect, coll, index) {
Meteor.call("doMeteorCall", "doMeteorCall", "insertObjects", coll._name, {name: "foo"}, 1, expect(function (err1, ids) {
@@ -2349,7 +2351,7 @@ function functionChain2Insert (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'foo');
}));
};
}
function functionChain2Upsert (test, expect, coll, index) {
var upsertId = '123456' + index;
@@ -2361,7 +2363,7 @@ function functionChain2Upsert (test, expect, coll, index) {
test.isTrue(_.isObject(o));
test.equal(o.name, 'foo');
}));
};
}
_.each( {collectionInsert: collectionInsert,
collectionUpsert: collectionUpsert,
@@ -2999,9 +3001,7 @@ _.extend(TestCustomType.prototype, {
return new TestCustomType(this.myHead, this.myTail);
},
equals: function (other) {
return other instanceof TestCustomType
&& EJSON.equals(this.myHead, other.myHead)
&& EJSON.equals(this.myTail, other.myTail);
return other instanceof TestCustomType && EJSON.equals(this.myHead, other.myHead) && EJSON.equals(this.myTail, other.myTail);
},
typeName: function () {
return 'someCustomType';
@@ -3367,23 +3367,23 @@ if (Meteor.isServer) {
coll.insert({animal: 'platypus', legs: 4});
coll.insert({animal: 'starfish', legs: 5});
var affected = coll.update({legs: 4}, {$set: {category: 'quadruped'}})
var affected = coll.update({legs: 4}, {$set: {category: 'quadruped'}});
test.equal(affected, 1);
//Changes only 3 but matched 4 documents
var affected = coll.update({legs: 4}, {$set: {category: 'quadruped'}}, {multi: true})
affected = coll.update({legs: 4}, {$set: {category: 'quadruped'}}, {multi: true});
test.equal(affected, 4);
//Again, changes nothing but returns nModified
var affected = coll.update({legs: 4}, {$set: {category: 'quadruped'}}, {multi: true})
affected = coll.update({legs: 4}, {$set: {category: 'quadruped'}}, {multi: true});
test.equal(affected, 4);
//upsert:true changes nothing, 4 modified
var affected = coll.update({legs: 4}, {$set: {category: 'quadruped'}}, {multi: true, upsert:true})
affected = coll.update({legs: 4}, {$set: {category: 'quadruped'}}, {multi: true, upsert:true});
test.equal(affected, 4);
//upsert method works as upsert:true
var result = coll.upsert({legs: 4}, {$set: {category: 'quadruped'}}, {multi: true})
var result = coll.upsert({legs: 4}, {$set: {category: 'quadruped'}}, {multi: true});
test.equal(result.numberAffected, 4);
});
@@ -3401,8 +3401,8 @@ if (Meteor.isServer) {
coll.update({legs: 4}, {$set: {category: 'quadruped'}}, function (err, result) {
test.equal(result, 1);
test2();
})
}
});
};
var test2 = function () {
//Changes only 3 but matched 4 documents
@@ -3410,7 +3410,7 @@ if (Meteor.isServer) {
test.equal(result, 4);
test3();
});
}
};
var test3 = function () {
//Again, changes nothing but returns nModified
@@ -3418,7 +3418,7 @@ if (Meteor.isServer) {
test.equal(result, 4);
test4();
});
}
};
var test4 = function () {
//upsert:true changes nothing, 4 modified
@@ -3426,7 +3426,7 @@ if (Meteor.isServer) {
test.equal(result, 4);
test5();
});
}
};
var test5 = function () {
//upsert method works as upsert:true
@@ -3434,7 +3434,7 @@ if (Meteor.isServer) {
test.equal(result.numberAffected, 4);
onComplete();
});
}
};
test1();
});