From ea47f4801e5210aa3c99237d465ad19fb7bdc98b Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Sat, 18 Sep 2021 18:17:42 +0000 Subject: SERVER-59962 clean up geo_array1.js to use different collection name for each test case --- jstests/core/geo_array1.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'jstests') diff --git a/jstests/core/geo_array1.js b/jstests/core/geo_array1.js index 6066ed1dc6f..2eba2c047c4 100644 --- a/jstests/core/geo_array1.js +++ b/jstests/core/geo_array1.js @@ -1,13 +1,23 @@ // Make sure many locations in one doc works, in the form of an array +// @tags: [ +// does_not_support_stepdowns, +// ] + +(function() { +'use strict'; + +const collNamePrefix = 'geo_array1_'; +let collCount = 0; -t = db.geoarray1; function test(index) { + let t = db.getCollection(collNamePrefix + collCount++); t.drop(); - var locObj = []; + const numLocations = 300; + let locObj = []; // Add locations everywhere - for (var i = 0; i < 10; i++) { - for (var j = 0; j < 10; j++) { + for (let i = 0; i < 10; i++) { + for (let j = 0; j < 10; j++) { if (j % 2 == 0) locObj.push([i, j]); else @@ -16,23 +26,28 @@ function test(index) { } // Add docs with all these locations - for (var i = 0; i < 300; i++) { - t.insert({loc: locObj}); + for (let i = 0; i < numLocations; i++) { + assert.commandWorked(t.insert({loc: locObj})); } if (index) { - t.createIndex({loc: "2d"}); + assert.commandWorked(t.createIndex({loc: "2d"})); } // Pull them back - for (var i = 0; i < 10; i++) { - for (var j = 0; j < 10; j++) { - assert.eq( - 300, - t.find({loc: {$within: {$box: [[i - 0.5, j - 0.5], [i + 0.5, j + 0.5]]}}}).count()); + for (let i = 0; i < 10; i++) { + for (let j = 0; j < 10; j++) { + const locations = t.find({ + loc: {$within: {$box: [[i - 0.5, j - 0.5], [i + 0.5, j + 0.5]]}} + }).toArray(); + assert.eq(numLocations, + locations.length, + 'index: ' + index + '; i: ' + i + '; j: ' + j + + '; locations: ' + tojson(locations)); } } } test(true); test(false); +})(); -- cgit v1.2.1