"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.stressOptions = exports.longOptions = exports.defaultOptions = exports.debugOptions = void 0;
const stochastic_test_utils_1 = require("@fluid-private/stochastic-test-utils");
const mergeTreeOperationRunner_js_1 = require("./mergeTreeOperationRunner.js");
const testClient_js_1 = require("./testClient.js");
const allOperations = [mergeTreeOperationRunner_js_1.removeRange, mergeTreeOperationRunner_js_1.annotateRange, mergeTreeOperationRunner_js_1.insertAtRefPos];
exports.debugOptions = {
    minLength: { min: 1, max: 512 },
    clients: { min: 1, max: 8 },
    opsPerRoundRange: { min: 1, max: 128 },
    rounds: 8,
    operations: allOperations,
    incrementalLog: true,
    growthFunc: (input) => input * 2,
    // resultsFilePostfix: `conflict-farm-with-obliterate-2.3.0.json`,
};
exports.defaultOptions = {
    minLength: { min: 1, max: 512 },
    clients: { min: 1, max: 8 },
    opsPerRoundRange: { min: 1, max: 128 },
    rounds: 8,
    operations: allOperations,
    growthFunc: (input) => input * 2,
};
exports.longOptions = {
    minLength: { min: 1, max: 512 },
    clients: { min: 1, max: 32 },
    opsPerRoundRange: { min: 1, max: 512 },
    rounds: 32,
    operations: allOperations,
    growthFunc: (input) => input * 2,
};
exports.stressOptions = {
    minLength: { min: 1, max: 512 },
    clients: { min: 1, max: 32 },
    opsPerRoundRange: { min: 1, max: 128 },
    rounds: 32,
    operations: allOperations,
    growthFunc: (input) => input * 2,
};
// Generate a list of single character client names, support up to 69 clients
const clientNames = (0, mergeTreeOperationRunner_js_1.generateClientNames)();
function runConflictFarmTests(opts, extraSeed) {
    (0, mergeTreeOperationRunner_js_1.doOverRange)(opts.minLength, opts.growthFunc, (minLength) => {
        for (const { name, config } of [
            {
                name: "applyOpsDuringGeneration",
                config: { ...opts, applyOpDuringGeneration: true },
            },
            {
                name: "obliterate with number endpoints",
                config: {
                    ...opts,
                    operations: [...opts.operations, mergeTreeOperationRunner_js_1.obliterateRange],
                },
            },
            // TODO: AB#15630
            // {
            // 	name: "obliterate with sided endpoints",
            // 	config: {
            // 		...opts,
            // 		operations: [...opts.operations, obliterateRange, obliterateRangeSided],
            // 	},
            // },
        ])
            it(`${name}: ConflictFarm_${minLength}`, async () => {
                const random = (0, stochastic_test_utils_1.makeRandom)(0xdeadbeef, 0xfeedbed, minLength, extraSeed ?? 0);
                const clients = [
                    new testClient_js_1.TestClient({
                        mergeTreeEnableObliterate: true,
                        mergeTreeEnableSidedObliterate: true,
                        mergeTreeEnableAnnotateAdjust: true,
                    }),
                ];
                for (const [i, c] of clients.entries())
                    c.startOrUpdateCollaboration(clientNames[i]);
                let seq = 0;
                while (clients.length < config.clients.max) {
                    for (const c of clients)
                        c.updateMinSeq(seq);
                    // Add double the number of clients each iteration
                    const targetClients = Math.max(config.clients.min, config.growthFunc(clients.length));
                    for (let cc = clients.length; cc < targetClients; cc++) {
                        const newClient = await testClient_js_1.TestClient.createFromClientSnapshot(clients[0], clientNames[cc]);
                        clients.push(newClient);
                    }
                    seq = (0, mergeTreeOperationRunner_js_1.runMergeTreeOperationRunner)(random, seq, clients, minLength, config);
                }
            }).timeout(30 * 10000);
    });
}
(0, stochastic_test_utils_1.describeFuzz)("MergeTree.Client", ({ testCount, stressMode }) => {
    const opts = stressMode === stochastic_test_utils_1.StressMode.Short ? exports.defaultOptions : exports.stressOptions;
    // defaultOptions;
    // debugOptions;
    // longOptions;
    if (testCount > 1) {
        (0, mergeTreeOperationRunner_js_1.doOverRange)({ min: 0, max: testCount - 1 }, (x) => x + 1, (seed) => {
            describe(`with seed ${seed}`, () => {
                runConflictFarmTests(opts, seed);
            });
        });
    }
    else {
        runConflictFarmTests(opts);
    }
});
//# sourceMappingURL=client.conflictFarm.spec.js.map