<commit_before>var events = require('./events');
var test2 = require('./test-util').test2;
var dsl = require('./ringpop-assert');

// endpoints
// /admin/debugClear
// /admin/debugSet
// /admin/lookup
// /admin/stats

test2('endpoint: /admin/gossip/stop', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        dsl.callEndpoint(t, tc, '/admin/gossip/stop'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipStop,
            direction: 'response'
        }, "Wait for AdminGossipStop response", function (response) {
            return true;
        }),

        dsl.consumePings(t, tc),
        dsl.wait(1000), // normally you would expect pings to be transfered in this time

        dsl.expectOnlyPings(t, tc, 0)
    ];
});

test2('endpoint: /admin/gossip/start', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        dsl.callEndpoint(t, tc, '/admin/gossip/stop'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipStop,
            direction: 'response'
        }, "Wait for AdminGossipStop response", function (response) {
            return true;
        }),

        dsl.consumePings(t, tc),
        dsl.wait(1000), // normally you would expect pings to be transfered in this time

        dsl.expectOnlyPings(t, tc, 0),

        dsl.callEndpoint(t, tc, '/admin/gossip/start'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipStart,
            direction: 'response'
        }, "Wait for AdminGossipStart response", function (response) {
            return true;
        }),

        dsl.waitForPing(t, tc),
        dsl.expectOnlyPings(t, tc)
    ];
});

test2('endpoint: /admin/gossip/tick', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        // stop gossip before invoking tick to make sure the tick is from the invocation
        dsl.callEndpoint(t, tc, '/admin/gossip/stop'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipStop,
            direction: 'response'
        }, "Wait for AdminGossipStop response", function (response) {
            return true;
        }),

        dsl.consumePings(t, tc),
        dsl.wait(1000), // normally you would expect pings to be transfered in this time

        dsl.expectOnlyPings(t, tc, 0),

        dsl.callEndpoint(t, tc, '/admin/gossip/tick'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipTick,
            direction: 'response'
        }, "Wait for AdminGossipTick response", function (response) {
            console.log("responded!");
            return true;
        }),

        dsl.wait(1000), // make sure it only send 1 ping

        dsl.expectOnlyPings(t, tc, 1)
    ];
});

test2('endpoint: /admin/lookup', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        dsl.callEndpoint(t, tc, '/admin/lookup', { key: 'Hello World' }),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminLookup,
            direction: 'response'
        }, "Wait for AdminLookup response", function (response) {
            // TODO test if the key is mapped to the right node
            return true;
        }),

        dsl.expectOnlyPings(t, tc)
    ];
});
<commit_msg>Add test invocation of /admin/stats.<commit_after>var events = require('./events');
var test2 = require('./test-util').test2;
var dsl = require('./ringpop-assert');

// TODO endpoints
//   /admin/debugClear (NOOP in go, toggle between ping logs in node2)
//   /admin/debugSet
// node only:
//   /admin/join
//   /admin/leave
//   /admin/reload

test2('endpoint: /admin/gossip/stop', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        dsl.callEndpoint(t, tc, '/admin/gossip/stop'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipStop,
            direction: 'response'
        }, "Wait for AdminGossipStop response", function (response) {
            return true;
        }),

        dsl.consumePings(t, tc),
        dsl.wait(1000), // normally you would expect pings to be transfered in this time

        dsl.expectOnlyPings(t, tc, 0)
    ];
});

test2('endpoint: /admin/gossip/start', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        dsl.callEndpoint(t, tc, '/admin/gossip/stop'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipStop,
            direction: 'response'
        }, "Wait for AdminGossipStop response", function (response) {
            return true;
        }),

        dsl.consumePings(t, tc),
        dsl.wait(1000), // normally you would expect pings to be transfered in this time

        dsl.expectOnlyPings(t, tc, 0),

        dsl.callEndpoint(t, tc, '/admin/gossip/start'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipStart,
            direction: 'response'
        }, "Wait for AdminGossipStart response", function (response) {
            return true;
        }),

        dsl.waitForPing(t, tc),
        dsl.expectOnlyPings(t, tc)
    ];
});

test2('endpoint: /admin/gossip/tick', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        // stop gossip before invoking tick to make sure the tick is from the invocation
        dsl.callEndpoint(t, tc, '/admin/gossip/stop'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipStop,
            direction: 'response'
        }, "Wait for AdminGossipStop response", function (response) {
            return true;
        }),

        dsl.consumePings(t, tc),
        dsl.wait(1000), // normally you would expect pings to be transfered in this time

        dsl.expectOnlyPings(t, tc, 0),

        dsl.callEndpoint(t, tc, '/admin/gossip/tick'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminGossipTick,
            direction: 'response'
        }, "Wait for AdminGossipTick response", function (response) {
            console.log("responded!");
            return true;
        }),

        dsl.wait(1000), // make sure it only send 1 ping

        dsl.expectOnlyPings(t, tc, 1)
    ];
});

test2('endpoint: /admin/lookup', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        dsl.callEndpoint(t, tc, '/admin/lookup', { key: 'Hello World' }),
        dsl.validateEventBody(t, tc, {
            type: events.Types.AdminLookup,
            direction: 'response'
        }, "Wait for AdminLookup response", function (response) {
            // TODO test if the key is mapped to the right node
            return true;
        }),

        dsl.expectOnlyPings(t, tc)
    ];
});

test2('endpoint: /admin/stats', 7, 5000, function(t, tc, n) {
    return [
        dsl.waitForJoins(t, tc, n),
        dsl.assertStats(t, tc, n+1, 0, 0),

        dsl.callEndpoint(t, tc, '/admin/stats'),
        dsl.validateEventBody(t, tc, {
            type: events.Types.Stats,
            direction: 'response'
        }, "Wait for Stats response", function (response) {
            // TODO do validation of specific values, the payload structure is already validated
            return true;
        }),

        dsl.expectOnlyPings(t, tc)
    ];
});

{'fraction_non_alphanumeric': 0.13916320166320167, 'fraction_numerical': 0.016632016632016633, 'mean_word_length': 2.135234215885947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4898851', 'n_tokens_mistral': 2574, 'n_tokens_neox': 2504, 'n_words': 618}