summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/ttl_expire_nan_warning_on_startup.js
blob: bf97a4a29130e997aea47e42656b77742403f09e (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
/**
 * Tests that a server containing a TTL index with NaN for 'expireAfterSeconds'
 * will log a warning on startup.
 *
 * @tags: [
 *     requires_persistence,
 *     requires_replication,
 * ]
 */
(function() {
'use strict';

load("jstests/libs/fail_point_util.js");
load('jstests/noPassthrough/libs/index_build.js');

const rst = new ReplSetTest({nodes: [{}, {rsConfig: {votes: 0, priority: 0}}]});
rst.startSet();
rst.initiate();

let primary = rst.getPrimary();
const db = primary.getDB('test');
const coll = db.t;

// The test cases here revolve around having a TTL index in the catalog with a NaN
// 'expireAfterSeconds'. The current createIndexes behavior will overwrite NaN with int32::max
// unless we use a fail point.
const fp = configureFailPoint(primary, 'skipTTLIndexValidationOnCreateIndex');
const fp2 =
    configureFailPoint(primary, 'skipTTLIndexInvalidExpireAfterSecondsValidationForCreateIndex');
try {
    assert.commandWorked(coll.createIndex({t: 1}, {expireAfterSeconds: NaN}));
} finally {
    fp.off();
    fp2.off();
}

assert.commandWorked(coll.insert({_id: 0, t: ISODate()}));

// Force checkpoint in storage engine to ensure index is part of the catalog in
// in finished state at startup.
rst.awaitReplication();
let secondary = rst.getSecondary();
assert.commandWorked(secondary.adminCommand({fsync: 1}));

// Restart the secondary and check for the startup warning in the logs.
secondary = rst.restart(secondary);
rst.waitForState(secondary, ReplSetTest.State.SECONDARY);

// Wait for "Found an existing TTL index with NaN 'expireAfterSeconds' in the catalog" log message.
checkLog.containsJson(secondary, 6852200, {
    ns: coll.getFullName(),
    spec: (spec) => {
        jsTestLog('TTL index on secondary at startup: ' + tojson(spec));
        return isNaN(spec.expireAfterSeconds);
    }
});

rst.stopSet();
})();