summaryrefslogtreecommitdiff
path: root/jstests/core/coveredIndex3.js
blob: 8b15b40e86259330e3a01c6fbef38f37afb0350d (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
// Check proper covered index handling when query and processGetMore yield.
// SERVER-4975
// @tags: [
//   uses_parallel_shell,
// ]

if (0) {  // SERVER-4975

    t = db.jstests_coveredIndex3;
    t2 = db.jstests_coveredIndex3_other;
    t.drop();
    t2.drop();

    function doTest(batchSize) {
        // Insert an array, which will make the { a:1 } index multikey and should disable covered
        // index
        // matching.
        p1 = startParallelShell(
            'for( i = 0; i < 60; ++i ) { \
                               db.jstests_coveredIndex3.save( { a:[ 2000, 2001 ] } ); \
                               sleep( 300 ); \
                           }');

        // Frequent writes cause the find operation to yield.
        p2 = startParallelShell(
            'for( i = 0; i < 1800; ++i ) { \
                            db.jstests_coveredIndex3_other.save( {} ); \
                            sleep( 10 ); \
                            }');

        for (i = 0; i < 30; ++i) {
            t.drop();
            t.createIndex({a: 1});

            for (j = 0; j < 1000; ++j) {
                t.save({a: j});
            }

            c = t.find({}, {_id: 0, a: 1}).hint({a: 1}).batchSize(batchSize);
            while (c.hasNext()) {
                o = c.next();
                // If o contains a high numeric 'a' value, it must come from an array saved in p1.
                assert(!(o.a > 1500), 'improper object returned ' + tojson(o));
            }
        }

        p1();
        p2();
    }

    doTest(2000);  // Test query.
    doTest(
        500);  // Try to test getMore - not clear if this will actually trigger the getMore issue.
}