summaryrefslogtreecommitdiff
path: root/jstests/core/recursion.js
blob: ce4ed5dc4010204ec7f113f51db9a8e8fed4a814 (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
// Basic tests for a form of stack recursion that's been shown to cause C++ side stack overflows in
// the past. See SERVER-19614.
//
// The test runs commands that are not allowed with security token: mapReduce.
// @tags: [
//   not_allowed_with_security_token,
//   does_not_support_stepdowns,
//   requires_non_retryable_commands,
//   uses_map_reduce_with_temp_collections,
//   # This test has statements that do not support non-local read concern.
//   does_not_support_causal_consistency,
// ]

(function() {
"use strict";

db.recursion.drop();

// Make sure the shell doesn't blow up.
function shellRecursion() {
    shellRecursion.apply();
}
assert.throws(shellRecursion);

// Make sure server side stack overflow doesn't blow up.
function mapReduceRecursion() {
    db.recursion.mapReduce(
        function() {
            (function recursion() {
                recursion.apply();
            })();
        },
        function() {},
        {out: {merge: 'out_coll'}});
}

assert.commandWorked(db.recursion.insert({}));
assert.commandFailedWithCode(assert.throws(mapReduceRecursion), ErrorCodes.JSInterpreterFailure);
}());