summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/agg_match.js
blob: 00e23a24c03dbe38ec74fc13b8e299dee025b6df (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
'use strict';

/**
 * agg_match.js
 *
 * Runs an aggregation with a $match that returns half the documents.
 */
load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload
load('jstests/concurrency/fsm_workloads/agg_base.js'); // for $config

var $config = extendWorkload($config, function($config, $super) {

    $config.data.getOutCollName = function getOutCollName(collName) {
        return collName + '_out_agg_match';
    };

    $config.states.query = function query(db, collName) {
        // note that all threads output to the same collection
        var otherCollName = this.getOutCollName(collName);
        var cursor = db[collName].aggregate([
            { $match: { flag: true } },
            { $out: otherCollName }
        ]);
        assertAlways.eq(0, cursor.itcount(), 'cursor returned by $out should always be empty');
        // NOTE: This relies on the fast-path for .count() with no query being isolated.
        // NOTE: There's a bug, SERVER-3645, where .count() is wrong on sharded collections, so we
        // blacklisted this test for sharded clusters.
        assertWhenOwnColl.eq(db[collName].count() / 2, db[otherCollName].count());
    };

    $config.teardown = function teardown(db, collName, cluster) {
        $super.teardown.apply(this, arguments);

        assertWhenOwnColl(db[this.getOutCollName(collName)].drop());
    };

    return $config;
});