summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/drop_connections_sharded.js
blob: 7d2f605946e9fb118e0b24e22545f79fde4f67b1 (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
/**
 * verify dropConnections command works for sharded clusters
 * @tags: [requires_replication, requires_sharding]
 */

(function() {
    "use strict";

    const st = new ShardingTest({
        config: {nodes: 1},
        shards: 1,
        rs0: {nodes: 3},
        mongos: 1,
    });
    const mongos = st.s0;
    const rst = st.rs0;
    const primary = rst.getPrimary();

    mongos.adminCommand({multicast: {ping: 0}});

    function getConnPoolHosts() {
        const ret = mongos.adminCommand({connPoolStats: 1});
        assert.commandWorked(ret);
        jsTestLog("Connection pool stats by host: " + tojson(ret.hosts));
        return ret.hosts;
    }

    const cfg = primary.getDB('local').system.replset.findOne();
    const memberHost = cfg.members[2].host;
    assert.eq(memberHost in getConnPoolHosts(), true);

    const removedMember = cfg.members.splice(2, 1);
    assert.eq(removedMember[0].host, memberHost);
    cfg.version++;

    jsTestLog("Reconfiguring to omit " + memberHost);
    assert.commandWorked(primary.adminCommand({replSetReconfig: cfg}));
    assert.eq(memberHost in getConnPoolHosts(), true);

    jsTestLog("Dropping connections to " + memberHost);
    assert.commandWorked(mongos.adminCommand({dropConnections: 1, hostAndPort: [memberHost]}));
    assert.soon(() => {
        return !(memberHost in getConnPoolHosts());
    });

    // need to re-add removed node or test complain about the replset config
    cfg.members.push(removedMember[0]);
    cfg.version++;
    assert.commandWorked(primary.adminCommand({replSetReconfig: cfg}));

    st.stop();
})();