summaryrefslogtreecommitdiff
path: root/jstests/sharding/advance_logical_time_with_valid_signature.js
blob: ef2f5e44e812668d6804d012cc9ed8a9f051ca9c (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
/**
 * Tests that the mongo shell can use a cluster time with a valid signature to advance a server's
 * cluster time.
 */
(function() {
    "use strict";

    // Setup 2 mongos processes with mongobridge.
    let st = new ShardingTest({shards: 1, mongos: 2, useBridge: true, mongosWaitsForKeys: true});

    // Sever outgoing communications from the second mongos.
    st.s0.disconnect(st.s1);
    st._configServers.forEach(function(configSvr) {
        configSvr.disconnect(st.s1);
    });
    st._connections.forEach(function(conn) {
        conn.disconnect(st.s1);
    });

    let connectedDB = st.s0.getDB("test");
    let disconnectedDB = st.s1.getDB("test");

    // Send an insert to the connected mongos to advance its cluster time.
    let res = assert.commandWorked(connectedDB.runCommand({insert: "foo", documents: [{x: 1}]}));

    // Get logicalTime metadata from the connected mongos's response and send it in an isMaster
    // command to the disconnected mongos. isMaster does not require mongos to contact any other
    // servers, so the command should succeed.
    let lt = res.$clusterTime;
    res = assert.commandWorked(
        disconnectedDB.runCommand({isMaster: 1, $clusterTime: lt}),
        "expected the disconnected mongos to accept cluster time: " + tojson(lt));

    // Verify cluster time response from the disconnected mongos matches what was passed.
    assert.eq(lt,
              res.$clusterTime,
              "expected the disconnected mongos to send cluster time: " + tojson(lt) +
                  ", received: " + tojson(res.$clusterTime));

    st.stop();
})();