Improve testing
This commit is contained in:
parent
36633dfbcb
commit
cb3ffde342
3 changed files with 244 additions and 166 deletions
|
|
@ -3,87 +3,102 @@ import { MockAgent } from "./agent/mock-agent";
|
|||
import { sleep } from "./utils/sleep";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
const globalFiles: Record<string, Uint8Array> = {};
|
||||
const iterations = 100;
|
||||
const doDeletes = false;
|
||||
|
||||
async function runTest(): Promise<void> {
|
||||
console.info("Starting test");
|
||||
async function runTest({
|
||||
agentCount,
|
||||
concurrency,
|
||||
iterations,
|
||||
doDeletes
|
||||
}: {
|
||||
agentCount: number;
|
||||
concurrency: number;
|
||||
iterations: number;
|
||||
doDeletes: boolean;
|
||||
}): Promise<void> {
|
||||
console.info(
|
||||
`Running test with ${agentCount} agents, concurrency ${concurrency}, iterations ${iterations}, doDeletes ${doDeletes}`
|
||||
);
|
||||
|
||||
const initialSettings: Partial<SyncSettings> = {
|
||||
isSyncEnabled: true,
|
||||
token: "token",
|
||||
vaultName: uuidv4(),
|
||||
syncConcurrency: concurrency,
|
||||
remoteUri: "http://localhost:3030"
|
||||
};
|
||||
|
||||
const clients = [
|
||||
new MockAgent(
|
||||
globalFiles,
|
||||
initialSettings,
|
||||
"agent-1",
|
||||
"#ff0000",
|
||||
doDeletes
|
||||
),
|
||||
new MockAgent(
|
||||
globalFiles,
|
||||
initialSettings,
|
||||
"agent-2",
|
||||
"#00ff00",
|
||||
doDeletes
|
||||
),
|
||||
new MockAgent(
|
||||
globalFiles,
|
||||
initialSettings,
|
||||
"agent-3",
|
||||
"#0000ff",
|
||||
doDeletes
|
||||
),
|
||||
new MockAgent(
|
||||
globalFiles,
|
||||
initialSettings,
|
||||
"agent-4",
|
||||
"#ffaa00",
|
||||
doDeletes
|
||||
),
|
||||
new MockAgent(
|
||||
globalFiles,
|
||||
initialSettings,
|
||||
"agent-5",
|
||||
"#00ffaa",
|
||||
doDeletes
|
||||
)
|
||||
];
|
||||
|
||||
await Promise.all(clients.map(async (client) => client.init()));
|
||||
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
await Promise.all(clients.map(async (client) => client.act()));
|
||||
await sleep(100);
|
||||
const clients: MockAgent[] = [];
|
||||
for (let i = 0; i < agentCount; i++) {
|
||||
clients.push(
|
||||
new MockAgent(initialSettings, `agent-${i}`, "#ff0000", doDeletes)
|
||||
);
|
||||
}
|
||||
|
||||
await Promise.all(clients.map(async (client) => client.finish()));
|
||||
try {
|
||||
await Promise.all(clients.map(async (client) => client.init()));
|
||||
|
||||
console.info("Agents finished successfully");
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
console.info(`Iteration ${i + 1}/${iterations}`);
|
||||
await Promise.all(clients.map(async (client) => client.act()));
|
||||
await sleep(100);
|
||||
}
|
||||
|
||||
clients.forEach((client) => {
|
||||
console.info(`Checking consistency for ${client.name}`);
|
||||
client.assertFileSystemIsConsistent();
|
||||
console.info(`Consistency check for ${client.name} passed`);
|
||||
});
|
||||
for (const client of clients) {
|
||||
// todo: make it less hacky
|
||||
await client.finish();
|
||||
}
|
||||
|
||||
console.info("File systems found to be consistent");
|
||||
console.info("Agents finished successfully");
|
||||
|
||||
clients.forEach((client) => {
|
||||
console.info(`Checking content for ${client.name}`);
|
||||
client.assertAllContentIsPresentOnce();
|
||||
console.info(`Content check for ${client.name} passed`);
|
||||
});
|
||||
clients.slice(0, -1).forEach((client, i) => {
|
||||
console.info(
|
||||
`Checking consistency between ${client.name} and ${clients[i + 1].name}`
|
||||
);
|
||||
client.assertFileSystemsAreConsistent(clients[i]);
|
||||
console.info(`Consistency check for ${client.name} passed`);
|
||||
});
|
||||
|
||||
console.info("Test completed successfully");
|
||||
console.info("File systems found to be consistent");
|
||||
|
||||
clients.forEach((client) => {
|
||||
console.info(`Checking content for ${client.name}`);
|
||||
client.assertAllContentIsPresentOnce();
|
||||
console.info(`Content check for ${client.name} passed`);
|
||||
});
|
||||
|
||||
console.info(
|
||||
`Test passed with ${agentCount} agents, concurrency ${concurrency}, iterations ${iterations}, doDeletes ${doDeletes}`
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`Test failed with ${agentCount} agents, concurrency ${concurrency}, iterations ${iterations}, doDeletes ${doDeletes}`
|
||||
);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
runTest()
|
||||
async function runTests(): Promise<void> {
|
||||
const agentCounts = [2, 10];
|
||||
const concurrencies = [1, 16];
|
||||
const iterations = [300];
|
||||
const doDeletes = [false, true];
|
||||
|
||||
for (const agentCount of agentCounts) {
|
||||
for (const concurrency of concurrencies) {
|
||||
for (const iteration of iterations) {
|
||||
for (const deleteFiles of doDeletes) {
|
||||
await runTest({
|
||||
agentCount,
|
||||
concurrency,
|
||||
iterations: iteration,
|
||||
doDeletes: deleteFiles
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runTests()
|
||||
.then(() => {
|
||||
process.exit(0);
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue