summaryrefslogtreecommitdiff
path: root/jstests/libs/mongoebench.js
blob: a0d6f1b512d1735b221cacdb2c6b61b5eb5965f4 (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
"use strict";

var {runMongoeBench} = (function() {
    /**
     * Spawns a mongoebench process with the specified options.
     *
     * If a plain JavaScript object is specified as the 'config' parameter, then it is serialized to
     * a file as a JSON string which is then specified as the config file for the mongoebench
     * process.
     */
    function runMongoeBench(config, options = {}) {
        const args = ["mongoebench"];

        if (typeof config === "object") {
            const filename = MongoRunner.dataPath + "mongoebench_config.json";
            writeFile(filename, tojson(config));
            args.push(filename);
        } else if (typeof config === "string") {
            args.push(config);
        } else {
            throw new Error("'config' parameter must be a string or an object");
        }

        if (!options.hasOwnProperty("dbpath")) {
            options.dbpath = MongoRunner.dataDir;
        }

        for (let key of Object.keys(options)) {
            const value = options[key];
            if (value === null || value === undefined) {
                throw new Error(
                    "Value '" + value + "' for '" + key +
                    "' option is ambiguous; specify {flag: ''} to add --flag command line" +
                    " options'");
            }

            args.push("--" + key);
            if (value !== "") {
                args.push(value.toString());
            }
        }

        const exitCode = _runMongoProgram(...args);
        assert.eq(0, exitCode, "encountered an error in mongoebench");
    }

    return {runMongoeBench};
})();