"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_1 = require("./mergeTreeOperationRunner.cjs");
const testClient_1 = require("./testClient.cjs");
const allOperations = [mergeTreeOperationRunner_1.removeRange, mergeTreeOperationRunner_1.annotateRange, mergeTreeOperationRunner_1.insertAtRefPos];
exports.debugOptions = {
    minLength: { min: 1, max: 1 },
    clients: { min: 3, max: 3 },
    opsPerRoundRange: { min: 1, max: 100 },
    rounds: 1000,
    operations: allOperations,
    incrementalLog: true,
    growthFunc: (input) => input + 1,
};
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_1.generateClientNames)();
function runConflictFarmTests(opts, extraSeed) {
    (0, mergeTreeOperationRunner_1.doOverRange)(opts.minLength, opts.growthFunc, (minLength) => {
        it(`ConflictFarm_${minLength}`, async () => {
            const random = (0, stochastic_test_utils_1.makeRandom)(0xdeadbeef, 0xfeedbed, minLength, extraSeed ?? 0);
            const testOpts = { ...opts };
            if (extraSeed) {
                testOpts.resultsFilePostfix ?? (testOpts.resultsFilePostfix = "");
                testOpts.resultsFilePostfix += extraSeed;
            }
            const clients = [new testClient_1.TestClient()];
            clients.forEach((c, i) => c.startOrUpdateCollaboration(clientNames[i]));
            let seq = 0;
            while (clients.length < opts.clients.max) {
                clients.forEach((c) => c.updateMinSeq(seq));
                // Add double the number of clients each iteration
                const targetClients = Math.max(opts.clients.min, opts.growthFunc(clients.length));
                for (let cc = clients.length; cc < targetClients; cc++) {
                    const newClient = await testClient_1.TestClient.createFromClientSnapshot(clients[0], clientNames[cc]);
                    clients.push(newClient);
                }
                seq = (0, mergeTreeOperationRunner_1.runMergeTreeOperationRunner)(random, seq, clients, minLength, opts);
            }
        }).timeout(30 * 10000);
    });
}
(0, stochastic_test_utils_1.describeFuzz)("MergeTree.Client", ({ testCount, isStress }) => {
    const opts = isStress ? exports.stressOptions : exports.defaultOptions;
    // defaultOptions;
    // debugOptions;
    // longOptions;
    if (testCount > 1) {
        (0, mergeTreeOperationRunner_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.cjs.map