summaryrefslogtreecommitdiff
path: root/jstests/resmoke_selftest/shell_hang_analyzer.js
blob: 189f6fe1bba05c518673b12936d66ac10378a3d6 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'use strict';
(function() {

const anyLineMatches = function(lines, rex) {
    for (const line of lines) {
        if (line.match(rex)) {
            return true;
        }
    }
    return false;
};

(function() {

/*
 * This tests that calling runHangAnalyzer() actually runs the hang analyzer.
 */

const child = MongoRunner.runMongod();
clearRawMongoProgramOutput();

// drive-by test for enable(). Separate test for disable() below.
MongoRunner.runHangAnalyzer.disable();
MongoRunner.runHangAnalyzer.enable();

MongoRunner.runHangAnalyzer([child.pid]);

if (TestData && TestData.inEvergreen) {
    assert.soon(() => {
        // Ensure the hang-analyzer has killed the process.
        return !checkProgram(child.pid).alive;
    });

    const lines = rawMongoProgramOutput().split('\n');
    if (_isAddressSanitizerActive()) {
        assert.soon(() => {
            // On ASAN builds, we never dump the core during hang analyzer runs,
            // nor should the output be empty (empty means it didn't run).
            // If you're trying to debug why this test is failing, confirm that the
            // hang_analyzer_dump_core expansion has not been set to true.
            return !anyLineMatches(lines, /Dumping core/) && lines.length != 0;
        });
    } else {
        assert.soon(() => {
            // Outside of ASAN builds, we expect the core to be dumped.
            return anyLineMatches(lines, /Dumping core/);
        });
    }
} else {
    // When running locally the hang-analyzer is not run.
    MongoRunner.stopMongod(child);
}
})();

(function() {

/*
 * This tests the resmoke functionality of passing peer pids to TestData.
 */

assert(typeof TestData.peerPids !== 'undefined');

// ShardedClusterFixture 2 shards with 3 rs members per shard, 2 mongos's => 7 peers
assert.eq(7, TestData.peerPids.length);
})();

(function() {
/*
 * Test MongoRunner.runHangAnalzyzer.disable()
 */
clearRawMongoProgramOutput();

MongoRunner.runHangAnalyzer.disable();
MongoRunner.runHangAnalyzer([20200125]);

const lines = rawMongoProgramOutput().split('\n');
// Nothing should be executed, so there's no output.
assert.eq(lines, ['']);
})();

(function() {
/*
 * Test that hang analyzer doesn't run when running resmoke locally
 */
clearRawMongoProgramOutput();

const origInEvg = TestData.inEvergreen;

try {
    TestData.inEvergreen = false;
    MongoRunner.runHangAnalyzer.enable();
    MongoRunner.runHangAnalyzer(TestData.peerPids);
} finally {
    TestData.inEvergreen = origInEvg;
}

const lines = rawMongoProgramOutput().split('\n');
// Nothing should be executed, so there's no output.
assert.eq(lines, ['']);
})();
})();