diff options
author | Robert Guo <robert.guo@10gen.com> | 2016-03-22 13:20:14 -0400 |
---|---|---|
committer | Robert Guo <robert.guo@10gen.com> | 2016-05-18 13:47:18 -0400 |
commit | f2f6163b0b26f1b18951c3d4d0f88a833c344523 (patch) | |
tree | 6d5a4b8b8d9bcfdec12f5b34ce2afd0bede5b5bb /jstests/hooks | |
parent | 756d6ee26bcc3e219892475868ca145564559205 (diff) | |
download | mongo-f2f6163b0b26f1b18951c3d4d0f88a833c344523.tar.gz |
SERVER-22860 allow resmoke.py to run JS hooks
Diffstat (limited to 'jstests/hooks')
-rw-r--r-- | jstests/hooks/run_validate_collections.js | 16 | ||||
-rw-r--r-- | jstests/hooks/validate_collections.js | 35 |
2 files changed, 51 insertions, 0 deletions
diff --git a/jstests/hooks/run_validate_collections.js b/jstests/hooks/run_validate_collections.js new file mode 100644 index 00000000000..1e910b3e6cf --- /dev/null +++ b/jstests/hooks/run_validate_collections.js @@ -0,0 +1,16 @@ +// Runner for validateCollections that runs full validation on all collections when loaded into +// the mongo shell. +'use strict'; + +(function() { + assert.eq(typeof db, 'object', 'Invalid `db` object, is the shell connected to a mongod?'); + load('jstests/hooks/validate_collections.js'); // For validateCollections + + var dbNames = db.getMongo().getDBNames(); + + for (var dbName of dbNames) { + if (!validateCollections(db.getSiblingDB(dbName), {full: true})) { + throw new Error('Collection validation failed'); + } + } +})();
\ No newline at end of file diff --git a/jstests/hooks/validate_collections.js b/jstests/hooks/validate_collections.js new file mode 100644 index 00000000000..5024460f05a --- /dev/null +++ b/jstests/hooks/validate_collections.js @@ -0,0 +1,35 @@ +// Wrapper around the validate command that can be used to validate index key counts. +'use strict'; + +function validateCollections(db, obj) { + function dumpCollection(coll, limit) { + print('Printing indexes in: ' + coll.getFullName()); + printjson(coll.getIndexes()); + + print('Printing the first ' + limit + ' documents in: ' + coll.getFullName()); + var res = coll.find().limit(limit); + while (res.hasNext()) { + printjson(res.next()); + } + } + + assert.eq(typeof db, 'object', 'Invalid `db` object, is the shell connected to a mongod?'); + assert.eq(typeof obj, 'object', 'The `obj` argument must be an object'); + assert(obj.hasOwnProperty('full'), 'Please specify whether to use full validation'); + + var full = obj.full; + + var success = true; + var collNames = db.getCollectionNames(); + for (var collName of collNames) { + var coll = db.getCollection(collName); + var res = coll.validate(full); + + if (!res.ok || !res.valid) { + print('Collection validation failed with response: ' + tojson(res)); + dumpCollection(coll, 100); + success = false; + } + } + return success; +} |