This commit is contained in:
Andras Schmelczer 2025-03-02 10:25:38 +00:00
parent bcf48c428d
commit a2522ca44a
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
14 changed files with 1370 additions and 1040 deletions

View file

@ -46,27 +46,31 @@ export class MockAgent extends MockClient {
? "(online) "
: "(offline)";
const formatted = `[${this.name} ${state}] ${logLine.timestamp.toISOString()} ${logLine.level} ${logLine.message}`;
// HACK: we have to ensure the file has been synced if we want to change it offline without data loss
const historyEntry = /.*History entry: (.*.md).*/.exec(
logLine.message
);
if (historyEntry) {
this.doNotTouchWhileOffline =
this.doNotTouchWhileOffline.filter(
(file) => file !== historyEntry[1]
);
}
switch (logLine.level) {
case LogLevel.ERROR:
console.error(formatted);
// Let's not ignore errors
process.exit(1);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
sleep(1000).then(() => process.exit(1));
break;
case LogLevel.WARNING:
console.warn(formatted);
break;
case LogLevel.INFO:
// HACK: we have to ensure the file has been synced if we want to change it offline without data loss
const result = /.*History entry: (.*.md).*/.exec(
logLine.message
);
if (result) {
this.doNotTouchWhileOffline =
this.doNotTouchWhileOffline.filter(
(file) => file !== result[1]
);
}
console.info(formatted);
break;
case LogLevel.DEBUG:
@ -79,16 +83,17 @@ export class MockAgent extends MockClient {
}
public async act(): Promise<void> {
this.assertAllContentIsPresentOnce();
const options: (() => Promise<unknown>)[] = [
this.createFileAction.bind(this),
this.changeFetchChangesUpdateIntervalMsAction.bind(this)
];
if (
this.client.settings.getSettings().isSyncEnabled &&
this.doNotTouchWhileOffline.length === 0
) {
options.push(this.disableSyncAction.bind(this));
if (this.client.settings.getSettings().isSyncEnabled) {
if (this.doNotTouchWhileOffline.length === 0) {
options.push(this.disableSyncAction.bind(this));
}
} else {
options.push(this.enableSyncAction.bind(this));
}

View file

@ -38,6 +38,8 @@ async function runTest({
)
);
}
// for debugging
(globalThis as any).clients = clients;
try {
await Promise.all(clients.map(async (client) => client.init()));
@ -78,34 +80,32 @@ async function runTest({
console.info(`Content check for ${client.name} passed`);
});
console.info(`Test passed with ${settings}`);
console.info(`Test passed ${settings}`);
} catch (err) {
console.error(`Test failed with ${settings}`);
console.error(`Test failed ${settings}`);
throw err;
}
}
async function runTests(): Promise<void> {
const agentCounts = [2, 10];
const jitterScaleInSeconds = [0.5, 3, 0];
const jitterScaleInSeconds = [0, 0.5, 3];
const concurrencies = [1, 16];
const iterations = [50, 300];
const doDeletes = [false, true];
const doDeletes = [false];
for (const agentCount of agentCounts) {
for (const concurrency of concurrencies) {
for (const jitter of jitterScaleInSeconds) {
for (const iteration of iterations) {
for (const deleteFiles of doDeletes) {
while (true) {
await runTest({
agentCount,
concurrency,
iterations: iteration,
doDeletes: deleteFiles,
jitterScaleInSeconds: jitter
});
}
await runTest({
agentCount,
concurrency,
iterations: iteration,
doDeletes: deleteFiles,
jitterScaleInSeconds: jitter
});
}
}
}
@ -113,11 +113,24 @@ async function runTests(): Promise<void> {
}
}
process.on("uncaughtException", async (error) => {
console.error("Uncaught Exception:", error);
await sleep(1000);
process.exit(1);
});
process.on("unhandledRejection", async (reason, promise) => {
console.error("Unhandled Rejection:", reason);
await sleep(1000);
process.exit(1);
});
runTests()
.then(() => {
process.exit(0);
})
.catch((err: unknown) => {
.catch(async (err: unknown) => {
console.error(err);
await sleep(1000);
process.exit(1);
});