Add deterministic tests and lint
This commit is contained in:
parent
ea5a123cb8
commit
16afe31e89
29 changed files with 1738 additions and 222 deletions
|
|
@ -63,7 +63,10 @@ export class MockAgent extends MockClient {
|
|||
case LogLevel.ERROR:
|
||||
console.error(formatted);
|
||||
|
||||
if (!this.useSlowFileEvents && !formatted.includes("retrying in")) {
|
||||
if (
|
||||
!this.useSlowFileEvents &&
|
||||
!formatted.includes("retrying in")
|
||||
) {
|
||||
// Let's wait for the error to be caught if there was one
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
sleep(100).then(() => {
|
||||
|
|
@ -227,14 +230,14 @@ export class MockAgent extends MockClient {
|
|||
);
|
||||
this.client.logger.info(
|
||||
"Local files: " +
|
||||
Array.from(otherAgent.localFiles.keys()).join(", ")
|
||||
Array.from(otherAgent.localFiles.keys()).join(", ")
|
||||
);
|
||||
otherAgent.client.logger.info(
|
||||
"Local data: " + JSON.stringify(otherAgent.data, null, 2)
|
||||
);
|
||||
otherAgent.client.logger.info(
|
||||
"Local files: " +
|
||||
Array.from(otherAgent.localFiles.keys()).join(", ")
|
||||
Array.from(otherAgent.localFiles.keys()).join(", ")
|
||||
);
|
||||
|
||||
throw e;
|
||||
|
|
@ -307,7 +310,9 @@ export class MockAgent extends MockClient {
|
|||
`Decided to create file ${file} with content ${content}`
|
||||
);
|
||||
|
||||
return this.create(file, new TextEncoder().encode(` ${content} `), { ignoreSlowFileEvents: true });
|
||||
return this.create(file, new TextEncoder().encode(` ${content} `), {
|
||||
ignoreSlowFileEvents: true
|
||||
});
|
||||
}
|
||||
|
||||
private async disableSyncAction(): Promise<void> {
|
||||
|
|
@ -371,10 +376,14 @@ export class MockAgent extends MockClient {
|
|||
`Decided to update file ${file} with ${content}`
|
||||
);
|
||||
this.doNotTouchWhileOffline.push(file);
|
||||
await this.atomicUpdateText(file, (old) => ({
|
||||
text: old.text + ` ${content} `,
|
||||
cursors: []
|
||||
}), { ignoreSlowFileEvents: true });
|
||||
await this.atomicUpdateText(
|
||||
file,
|
||||
(old) => ({
|
||||
text: old.text + ` ${content} `,
|
||||
cursors: []
|
||||
}),
|
||||
{ ignoreSlowFileEvents: true }
|
||||
);
|
||||
}
|
||||
|
||||
private async deleteFileAction(files: RelativePath[]): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,9 @@ export class MockClient implements FileSystemOperations {
|
|||
public async create(
|
||||
path: RelativePath,
|
||||
newContent: Uint8Array,
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = { ignoreSlowFileEvents: false }
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = {
|
||||
ignoreSlowFileEvents: false
|
||||
}
|
||||
): Promise<void> {
|
||||
if (this.localFiles.has(path)) {
|
||||
throw new Error(`File ${path} already exists`);
|
||||
|
|
@ -75,9 +77,10 @@ export class MockClient implements FileSystemOperations {
|
|||
);
|
||||
this.localFiles.set(path, newContent);
|
||||
|
||||
this.executeFileOperation((async () =>
|
||||
this.client.syncLocallyCreatedFile(path)
|
||||
), ignoreSlowFileEvents);
|
||||
this.executeFileOperation(
|
||||
async () => this.client.syncLocallyCreatedFile(path),
|
||||
ignoreSlowFileEvents
|
||||
);
|
||||
}
|
||||
|
||||
public async createDirectory(_path: RelativePath): Promise<void> {
|
||||
|
|
@ -87,7 +90,9 @@ export class MockClient implements FileSystemOperations {
|
|||
public async atomicUpdateText(
|
||||
path: RelativePath,
|
||||
updater: (currentContent: TextWithCursors) => TextWithCursors,
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = { ignoreSlowFileEvents: false }
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = {
|
||||
ignoreSlowFileEvents: false
|
||||
}
|
||||
): Promise<string> {
|
||||
const file = this.localFiles.get(path);
|
||||
if (!file) {
|
||||
|
|
@ -104,13 +109,13 @@ export class MockClient implements FileSystemOperations {
|
|||
.map((part) => part.trim());
|
||||
const newParts = newContent.split(" ").map((part) => part.trim());
|
||||
existingParts.forEach((part) =>
|
||||
// all changes should be additive
|
||||
{
|
||||
assert(
|
||||
newParts.includes(part),
|
||||
`Part ${part} not found in new content: ${newContent}`
|
||||
);
|
||||
}
|
||||
// all changes should be additive
|
||||
{
|
||||
assert(
|
||||
newParts.includes(part),
|
||||
`Part ${part} not found in new content: ${newContent}`
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -118,11 +123,13 @@ export class MockClient implements FileSystemOperations {
|
|||
`Updated file ${path} with:\n current content: ${currentContent}\n new content: ${newContent}`
|
||||
);
|
||||
|
||||
this.executeFileOperation((async () =>
|
||||
this.client.syncLocallyUpdatedFile({
|
||||
relativePath: path
|
||||
})
|
||||
), ignoreSlowFileEvents);
|
||||
this.executeFileOperation(
|
||||
async () =>
|
||||
this.client.syncLocallyUpdatedFile({
|
||||
relativePath: path
|
||||
}),
|
||||
ignoreSlowFileEvents
|
||||
);
|
||||
|
||||
return newContent;
|
||||
}
|
||||
|
|
@ -146,21 +153,29 @@ export class MockClient implements FileSystemOperations {
|
|||
});
|
||||
}
|
||||
|
||||
public async delete(path: RelativePath, { ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = { ignoreSlowFileEvents: false }): Promise<void> {
|
||||
public async delete(
|
||||
path: RelativePath,
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = {
|
||||
ignoreSlowFileEvents: false
|
||||
}
|
||||
): Promise<void> {
|
||||
this.client.logger.info(
|
||||
`Deleting file: ${path} with:\n content ${new TextDecoder().decode(this.localFiles.get(path))}`
|
||||
);
|
||||
this.localFiles.delete(path);
|
||||
|
||||
this.executeFileOperation((async () =>
|
||||
this.client.syncLocallyDeletedFile(path)
|
||||
), ignoreSlowFileEvents);
|
||||
this.executeFileOperation(
|
||||
async () => this.client.syncLocallyDeletedFile(path),
|
||||
ignoreSlowFileEvents
|
||||
);
|
||||
}
|
||||
|
||||
public async rename(
|
||||
oldPath: RelativePath,
|
||||
newPath: RelativePath,
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = { ignoreSlowFileEvents: false }
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = {
|
||||
ignoreSlowFileEvents: false
|
||||
}
|
||||
): Promise<void> {
|
||||
const file = this.localFiles.get(oldPath);
|
||||
if (!file) {
|
||||
|
|
@ -175,15 +190,20 @@ export class MockClient implements FileSystemOperations {
|
|||
`Renamed file: ${oldPath} -> ${newPath} with:\n content ${new TextDecoder().decode(file)}`
|
||||
);
|
||||
|
||||
this.executeFileOperation((async () =>
|
||||
this.client.syncLocallyUpdatedFile({
|
||||
oldPath,
|
||||
relativePath: newPath
|
||||
})
|
||||
), ignoreSlowFileEvents);
|
||||
this.executeFileOperation(
|
||||
async () =>
|
||||
this.client.syncLocallyUpdatedFile({
|
||||
oldPath,
|
||||
relativePath: newPath
|
||||
}),
|
||||
ignoreSlowFileEvents
|
||||
);
|
||||
}
|
||||
|
||||
private executeFileOperation(callback: () => unknown, ignoreSlowFileEvents = false): void {
|
||||
private executeFileOperation(
|
||||
callback: () => unknown,
|
||||
ignoreSlowFileEvents = false
|
||||
): void {
|
||||
if (this.useSlowFileEvents && !ignoreSlowFileEvents) {
|
||||
// we aren't the best client and it takes some time to notice changes
|
||||
setTimeout(callback, Math.random() * 100);
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ async function runTest({
|
|||
slowFileEvents = useSlowFileEvents;
|
||||
doResets = useResets;
|
||||
|
||||
|
||||
|
||||
const settings = `with ${agentCount} agents, concurrency ${concurrency}, iterations ${iterations}, doDeletes ${doDeletes}, doResets ${useResets}, jitterScaleInSeconds ${jitterScaleInSeconds}, useSlowFileEvents ${useSlowFileEvents}`;
|
||||
logger.info(`Running test ${settings}`);
|
||||
|
||||
|
|
@ -70,7 +68,9 @@ async function runTest({
|
|||
await utils.awaitAll(clients.map(async (client) => client.init()));
|
||||
|
||||
for (const client of clients) {
|
||||
const initialDocCount = Math.floor(Math.random() * MAX_INITIAL_DOCS);
|
||||
const initialDocCount = Math.floor(
|
||||
Math.random() * MAX_INITIAL_DOCS
|
||||
);
|
||||
if (initialDocCount > 0) {
|
||||
logger.info(
|
||||
`Creating ${initialDocCount} initial documents for ${client.name}`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue