summaryrefslogtreecommitdiff
path: root/jstests/libs/override_methods/detect_spawning_own_mongod.js
blob: 42b95a58d5160ebbd6f75116322507dd66631bf0 (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
/**
 * Define overrides to prevent any test from spawning its own test fixture since certain passthrough
 * suites should not contain JS tests that start their own mongod/s.
 */
(function() {
'use strict';

MongoRunner.runMongod = function() {
    throw new Error("Detected MongoRunner.runMongod() call in js test from passthrough suite. " +
                    "Consider moving the test to one of the jstests/noPassthrough/, " +
                    "jstests/replsets/, or jstests/sharding/ directories.");
};

MongoRunner.runMongos = function() {
    throw new Error("Detected MongoRunner.runMongos() call in js test from passthrough suite. " +
                    "Consider moving the test to one of the jstests/noPassthrough/, " +
                    "jstests/replsets/, or jstests/sharding/ directories.");
};

const STOverrideConstructor = function() {
    throw new Error("Detected ShardingTest() call in js test from passthrough suite. " +
                    "Consider moving the test to one of the jstests/noPassthrough/, " +
                    "jstests/replsets/, or jstests/sharding/ directories.");
};

// This Object.assign() lets us modify ShardingTest to use the new overridden constructor but
// still keep any static properties it has.
ShardingTest = Object.assign(STOverrideConstructor, ShardingTest);

const RSTOverrideConstructor = function() {
    throw new Error("Detected ReplSetTest() call in js test from passthrough suite. " +
                    "Consider moving the test to one of the jstests/noPassthrough/, " +
                    "jstests/replsets/, or jstests/sharding/ directories.");
};

// Same as the above Object.assign() call. In particular, we want to preserve the
// ReplSetTest.kDefaultTimeoutMS property, which should be accessible to tests in the
// passthrough suite.
ReplSetTest = Object.assign(RSTOverrideConstructor, ReplSetTest);
})();