Skip to content

Commit 0519832

Browse files
author
Tad Marshall
committed
SERVER-9242 Add jstest for blockCheckSupported() features
Add test to make sure that db.serverStatus() returns workingSet and indexCounters values as expected on all platforms. Windows XP is expected to give different ("not supported") return values, make sure that they are as expected.
1 parent 56432a5 commit 0519832

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

jstests/block_check_supported.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Test that serverStatus() features dependent on the ProcessInfo::blockCheckSupported() routine
2+
// work correctly. These features are db.serverStatus({workingSet:1}).workingSet and
3+
// db.serverStatus().indexCounters.
4+
// Related to SERVER-9242, SERVER-6450.
5+
6+
// Check that an object contains a specific set of fields and only those fields
7+
// NOTE: destroys 'item'
8+
//
9+
var testExpectedFields = function(itemString, item, fieldList) {
10+
print('Testing ' + itemString + ' for expected fields');
11+
for (var i = 0; i < fieldList.length; ++i) {
12+
var field = fieldList[i];
13+
if (typeof item[field] == 'undefined') {
14+
doassert('Test FAILED: missing "' + field + '" field');
15+
}
16+
delete item[field];
17+
}
18+
if (!friendlyEqual({}, item)) {
19+
doassert('Test FAILED: found unexpected field(s): ' + tojsononeline(item));
20+
}
21+
}
22+
23+
// Run test as function to keep cruft out of global namespace
24+
//
25+
var doTest = function () {
26+
27+
print('Testing workingSet and indexCounters portions of serverStatus');
28+
var hostInfo = db.hostInfo();
29+
var isXP = (hostInfo.os.name == 'Windows XP') ? true : false;
30+
31+
// Check that the serverStatus command returns something for these sub-documents
32+
//
33+
var serverStatus = db.serverStatus({ workingSet: 1 });
34+
if (!serverStatus) {
35+
doassert('Test FAILED: db.serverStatus({workingSet:1}) did not return a value');
36+
}
37+
if (!serverStatus.workingSet) {
38+
doassert('Test FAILED: db.serverStatus({workingSet:1}).workingSet was not returned');
39+
}
40+
if (!serverStatus.indexCounters) {
41+
doassert('Test FAILED: db.serverStatus().indexCounters was not returned');
42+
}
43+
var workingSet_1 = serverStatus.workingSet;
44+
var indexCounters_1 = serverStatus.indexCounters;
45+
46+
if (isXP) {
47+
// Windows XP is the only supported platform that should be missing this data; make sure
48+
// that we don't get bogus data back
49+
//
50+
var expectedResult = { info: 'not supported' };
51+
print('Testing db.serverStatus({workingSet:1}).workingSet on Windows XP -- expecting ' +
52+
tojsononeline(expectedResult));
53+
assert.eq(expectedResult, workingSet_1,
54+
'Test FAILED: db.serverStatus({workingSet:1}).workingSet' +
55+
' did not return the expected value');
56+
expectedResult = { note: 'not supported on this platform' };
57+
print('Testing db.serverStatus().indexCounters on Windows XP -- expecting ' +
58+
tojsononeline(expectedResult));
59+
assert.eq(expectedResult, indexCounters_1,
60+
'Test FAILED: db.serverStatus().indexCounters' +
61+
' did not return the expected value');
62+
}
63+
else {
64+
// Check that we get both workingSet and indexCounters and that all expected
65+
// fields are present with no unexpected fields
66+
//
67+
testExpectedFields('db.serverStatus({workingSet:1}).workingSet',
68+
workingSet_1,
69+
['note', 'pagesInMemory', 'computationTimeMicros', 'overSeconds']);
70+
testExpectedFields('db.serverStatus().indexCounters',
71+
indexCounters_1,
72+
['accesses', 'hits', 'misses', 'resets', 'missRatio']);
73+
74+
if (0) { // comment out until SERVER-9284 is fixed
75+
// See if we can make the index counters values change
76+
//
77+
print('Testing that indexCounters accesses and hits increase by 1 on indexed find()');
78+
var blockDB = db.getSiblingDB('block_check_supported');
79+
blockDB.dropDatabase();
80+
blockDB.coll.insert({ a: 1 });
81+
blockDB.coll.ensureIndex({ a: 1 });
82+
indexCounters_1 = db.serverStatus().indexCounters;
83+
var doc = blockDB.coll.findOne({ a: 1 });
84+
var indexCounters_2 = db.serverStatus().indexCounters;
85+
assert.gt(indexCounters_2.accesses, indexCounters_1.accesses,
86+
'Test FAILED: db.serverStatus().indexCounters.accesses' +
87+
' should have had a value greater than ' + indexCounters_1.accesses +
88+
': indexCounters: before find(): ' + tojsononeline(indexCounters_1) +
89+
', after find(): ' + tojsononeline(indexCounters_2));
90+
assert.gt(indexCounters_2.hits, indexCounters_1.hits,
91+
'Test FAILED: db.serverStatus().indexCounters.hits' +
92+
' should have had a value greater than ' + indexCounters_1.hits +
93+
': indexCounters: before find(): ' + tojsononeline(indexCounters_1) +
94+
', after find(): ' + tojsononeline(indexCounters_2));
95+
} // comment out until SERVER-9284 is fixed
96+
}
97+
print('Test PASSED!');
98+
};
99+
100+
doTest();

0 commit comments

Comments
 (0)