blob: 3eb08e02fb965da7f16fe0229afc064319d47963 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Test that the dbhash command checks system collections that are replicated.
'use strict';
(function() {
var rst = new ReplSetTest({name: 'dbhash_system_collections', nodes: 2});
rst.startSet();
rst.initiate();
var primary = rst.getPrimary();
var secondary = rst.getSecondary();
var testDB = primary.getDB('test');
assert.commandWorked(testDB.system.users.insert({users: 1}));
assert.commandWorked(testDB.system.js.insert({js: 1}));
var adminDB = primary.getDB('admin');
assert.commandWorked(adminDB.system.roles.insert({roles: 1}));
assert.commandWorked(adminDB.system.version.insert({version: 1}));
assert.commandWorked(adminDB.system.backup_users.insert({backup_users: 1}));
rst.awaitReplication();
function checkDbHash(mongo) {
var testDB = mongo.getDB('test');
var adminDB = mongo.getDB('admin');
var replicatedSystemCollections = [
'system.js',
'system.users',
];
var replicatedAdminSystemCollections = [
'system.backup_users',
'system.keys',
'system.roles',
'system.version',
];
var res = testDB.runCommand('dbhash');
assert.commandWorked(res);
assert.docEq(Object.keys(res.collections), replicatedSystemCollections, tojson(res));
res = adminDB.runCommand('dbhash');
assert.commandWorked(res);
assert.docEq(Object.keys(res.collections), replicatedAdminSystemCollections, tojson(res));
return res.md5;
}
var primaryMd5 = checkDbHash(primary);
var secondaryMd5 = checkDbHash(secondary);
assert.eq(primaryMd5, secondaryMd5, 'dbhash is different on the primary and the secondary');
rst.stopSet();
})();
|