Skip to content

Commit

Permalink
SERVER-20086 Avoid closing over $config.data in FSM tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
visemet committed Sep 2, 2015
1 parent 7bb78ed commit 991e990
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
7 changes: 2 additions & 5 deletions jstests/concurrency/fsm_workloads/yield.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ load('jstests/concurrency/fsm_workload_helpers/server_types.js'); // for isMongo
*/
var $config = (function() {

// Define here so that both data.nDocs and data.genUpdateDoc can reference it
var nDocs = 200;

var data = {
// Number of docs to insert at the beginning.
nDocs: nDocs,
nDocs: 200,
// Batch size of queries to introduce more saving and restoring of states.
batchSize: 3,
// The words that can be found in the collection.
Expand Down Expand Up @@ -46,7 +43,7 @@ var $config = (function() {
* the update state should use for the update query.
*/
genUpdateDoc: function genUpdateDoc() {
var newVal = Random.randInt(nDocs);
var newVal = Random.randInt(this.nDocs);
return { $set: { a: newVal } };
}
};
Expand Down
16 changes: 8 additions & 8 deletions jstests/concurrency/fsm_workloads/yield_geo_near.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var $config = extendWorkload($config, function($config, $super) {
* environment. Unfortunately this means we cannot batch the request.
*/
$config.states.query = function geoNear(db, collName) {
// This distance gets about 80 docs around the origin. There is one doc inserted
// This distance gets about 80 docs around the origin. There is one doc inserted
// every 1m^2 and the area scanned by a 5m radius is PI*(5m)^2 ~ 79.
var maxDistance = 5;

Expand All @@ -35,11 +35,11 @@ var $config = extendWorkload($config, function($config, $super) {
};

$config.data.genUpdateDoc = function genUpdateDoc() {
var P = Math.floor(Math.sqrt($config.data.nDocs));
var P = Math.floor(Math.sqrt(this.nDocs));

// Move the point to another location within the PxP grid.
var newX = Random.randInt(P) - P/2;
var newY = Random.randInt(P) - P/2
var newY = Random.randInt(P) - P/2;
return { $set: { geo: [newX, newY] } };
};

Expand All @@ -56,20 +56,20 @@ var $config = extendWorkload($config, function($config, $super) {
*/
$config.setup = function setup(db, collName, cluster) {
$super.setup.apply(this, arguments);
var P = Math.floor(Math.sqrt($config.data.nDocs));

var P = Math.floor(Math.sqrt(this.nDocs));
var i = 0;
// Set up some points to query (in a PxP grid around 0,0).
var bulk = db[collName].initializeUnorderedBulkOp();
for (var x = 0; x < P; x++) {
for (var y = 0; y < P; y++) {
var coords = [x - P/2, y - P/2];
bulk.find({ _id: i }).upsert().replaceOne($config.data.getReplaceSpec(i, coords));
bulk.find({ _id: i }).upsert().replaceOne(this.getReplaceSpec(i, coords));
i++;
}
}
assertAlways.writeOK(bulk.execute());
assertAlways.commandWorked(db[collName].ensureIndex($config.data.getIndexSpec()));
assertAlways.commandWorked(db[collName].ensureIndex(this.getIndexSpec()));
};

return $config;
Expand Down
10 changes: 5 additions & 5 deletions jstests/concurrency/fsm_workloads/yield_geo_near_dedup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ var $config = extendWorkload($config, function($config, $super) {

/*
* Use geo $nearSphere query to find points near the origin. Note this should be done using the
* geoNear command, rather than a $nearSphere query, as the $nearSphere query doesn't work in a
* geoNear command, rather than a $nearSphere query, as the $nearSphere query doesn't work in a
* sharded environment. Unfortunately this means we cannot batch the request.
*
*
* Only points are covered in this test as there is no guarantee that geometries indexed in
* multiple cells will be deduplicated correctly with interspersed updates. If multiple index
* multiple cells will be deduplicated correctly with interspersed updates. If multiple index
* cells for the same geometry occur in the same search interval, an update may cause geoNear
* to return the same document multiple times.
*/
$config.states.query = function geoNear(db, collName) {
// This distance gets about 80 docs around the origin. There is one doc inserted
// This distance gets about 80 docs around the origin. There is one doc inserted
// every 1m^2 and the area scanned by a 5m radius is PI*(5m)^2 ~ 79.
var maxDistance = 5;

Expand All @@ -31,7 +31,7 @@ var $config = extendWorkload($config, function($config, $super) {
maxDistance: maxDistance,
spherical: true
});
assertWhenOwnColl.commandWorked(res);
assertWhenOwnColl.commandWorked(res);
assertWhenOwnColl(function verifyResults() {
var results = res.results;
// TODO: Support non-primitive _id
Expand Down
4 changes: 2 additions & 2 deletions jstests/concurrency/fsm_workloads/yield_rooted_or.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var $config = extendWorkload($config, function($config, $super) {
};

$config.data.genUpdateDoc = function genUpdateDoc() {
var newC = Random.randInt($config.data.nDocs);
var newD = Random.randInt($config.data.nDocs);
var newC = Random.randInt(this.nDocs);
var newD = Random.randInt(this.nDocs);
return { $set: { c: newC, d: newD } };
};

Expand Down
4 changes: 2 additions & 2 deletions jstests/concurrency/fsm_workloads/yield_sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ var $config = extendWorkload($config, function($config, $super) {
};

$config.data.genUpdateDoc = function genUpdateDoc() {
var newA = Random.randInt($config.data.nDocs);
var newC = Random.randInt($config.data.nDocs);
var newA = Random.randInt(this.nDocs);
var newC = Random.randInt(this.nDocs);
return { $set: { a: newA, c: newC } };
};

Expand Down
4 changes: 2 additions & 2 deletions jstests/concurrency/fsm_workloads/yield_sort_merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ var $config = extendWorkload($config, function($config, $super) {
};

$config.data.genUpdateDoc = function genUpdateDoc() {
var newA = Random.randInt($config.data.nDocs);
var newB = Random.randInt($config.data.nDocs);
var newA = Random.randInt(this.nDocs);
var newB = Random.randInt(this.nDocs);
return { $set: { a: newA, b: newB } };
};

Expand Down
2 changes: 1 addition & 1 deletion jstests/concurrency/fsm_workloads/yield_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var $config = extendWorkload($config, function($config, $super) {
};

$config.data.genUpdateDoc = function genUpdateDoc() {
var newWord = $config.data.words[Random.randInt($config.data.words.length)];
var newWord = this.words[Random.randInt(this.words.length)];
return { $set: { yield_text: newWord } };
};

Expand Down

0 comments on commit 991e990

Please sign in to comment.