diff --git a/frontend/test-client/src/agent/mock-agent.ts b/frontend/test-client/src/agent/mock-agent.ts index 80413fe0..42d9490d 100644 --- a/frontend/test-client/src/agent/mock-agent.ts +++ b/frontend/test-client/src/agent/mock-agent.ts @@ -108,32 +108,40 @@ export class MockAgent extends MockClient { } } - if (Math.random() < 0.1 && this.doResets) { - options.push(this.resetClient.bind(this)); + if (Math.random() < 0.015 && this.doResets) { + // we can't just queue this up as once it's destroyed, no more method calls can go to SyncClient + await this.resetClient(); + } else { + this.pendingActions.push( + (async (): Promise => { + try { + return await choose(options)(); + } catch (error) { + this.client.logger.error( + `Failed to perform an action: ${error}` + ); + this.client.logger.info( + JSON.stringify(this.data, null, 2) + ); + this.client.logger.info( + JSON.stringify(this.localFiles, null, 2) + ); + throw error; + } + })() + ); } - - this.pendingActions.push( - (async (): Promise => { - try { - return await choose(options)(); - } catch (error) { - this.client.logger.error( - `Failed to perform an action: ${error}` - ); - this.client.logger.info(JSON.stringify(this.data, null, 2)); - this.client.logger.info( - JSON.stringify(this.localFiles, null, 2) - ); - throw error; - } - })() - ); } public async finish(): Promise { await this.client.setSetting("isSyncEnabled", true); // eslint-disable-next-line no-restricted-properties await Promise.all(this.pendingActions); + await this.client.waitUntilFinished(); + } + + public async destroy(): Promise { + await this.client.waitUntilFinished(); await this.client.destroy(); } diff --git a/frontend/test-client/src/cli.ts b/frontend/test-client/src/cli.ts index 7b81f800..531cf102 100644 --- a/frontend/test-client/src/cli.ts +++ b/frontend/test-client/src/cli.ts @@ -82,7 +82,7 @@ async function runTest({ // then we need a second pass to ensure that all agents pull the same state. for (const client of clients) { try { - await client.finish(); + await client.destroy(); } catch (err) { if (!slowFileEvents) { throw err; @@ -116,17 +116,17 @@ async function runTest({ } async function runTests(): Promise { - await runTest({ - agentCount: 2, - concurrency: 16, - iterations: 100, - doDeletes: true, - doResets: true, - useSlowFileEvents: true, - jitterScaleInSeconds: 0.75 - }); - for (let i = 0; i < TEST_ITERATIONS; i++) { + await runTest({ + agentCount: 2, + concurrency: 16, + iterations: 100, + doDeletes: true, + doResets: true, + useSlowFileEvents: true, + jitterScaleInSeconds: 0.75 + }); + for (const useSlowFileEvents of [false, true]) { for (const concurrency of [ 16,