From fbbd6c5a0362a03cf30d83f36f090bfe290cb50c Mon Sep 17 00:00:00 2001 From: phancb Date: Fri, 17 Nov 2023 15:16:58 +0800 Subject: [PATCH 1/3] chore: fix flaky test for slow machines --- .../typescript/features/CompletionProvider.test.ts | 2 +- .../typescript/features/DiagnosticsProvider.test.ts | 8 ++++---- .../test/plugins/typescript/test-utils.ts | 4 +++- .../plugins/typescript/typescript-performance.test.ts | 11 ++++++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts b/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts index ee6ee4acf..8e674cde1 100644 --- a/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts @@ -1041,7 +1041,7 @@ describe('CompletionProviderImpl', function () { const item = completions?.items?.[0]; assert.strictEqual(item?.label, 'abc'); } - }).timeout(4000); + }); it('provides default slot-let completion for components with type definition', async () => { const { completionProvider, document } = setup('component-events-completion-ts-def.svelte'); diff --git a/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts b/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts index b01473ef0..5e8810928 100644 --- a/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts @@ -55,7 +55,7 @@ describe('DiagnosticsProvider', function () { const diagnostics3 = await plugin.getDiagnostics(document); assert.deepStrictEqual(diagnostics3.length, 1); - }).timeout(5000); + }); it('notices changes of module resolution because of new file', async () => { const { plugin, document, lsAndTsDocResolver } = setup('unresolvedimport.svelte'); @@ -90,7 +90,7 @@ describe('DiagnosticsProvider', function () { unlinkSync(newTsFilePath); unlinkSync(newFilePath); } - }).timeout(5000); + }); it('notices update of imported module', async () => { const { plugin, document, lsAndTsDocResolver } = setup( @@ -116,7 +116,7 @@ describe('DiagnosticsProvider', function () { const diagnostics2 = await plugin.getDiagnostics(document); assert.deepStrictEqual(diagnostics2.length, 0); await lsAndTsDocResolver.deleteSnapshot(newFilePath); - }).timeout(5000); + }); it('notices file changes in all services that reference that file', async () => { // Hacky but ensures that this tests is not interfered with by other tests @@ -169,5 +169,5 @@ describe('DiagnosticsProvider', function () { assert.deepStrictEqual(diagnostics3.length, 0); const diagnostics4 = await plugin.getDiagnostics(otherDocument); assert.deepStrictEqual(diagnostics4.length, 0); - }).timeout(5000); + }).timeout(this.timeout() * 2.5); }); diff --git a/packages/language-server/test/plugins/typescript/test-utils.ts b/packages/language-server/test/plugins/typescript/test-utils.ts index f8f0c7f1d..522471464 100644 --- a/packages/language-server/test/plugins/typescript/test-utils.ts +++ b/packages/language-server/test/plugins/typescript/test-utils.ts @@ -255,7 +255,9 @@ export async function createJsonSnapshotFormatter(dir: string) { export function serviceWarmup(suite: Mocha.Suite, testDir: string, rootUri = pathToUrl(testDir)) { const defaultTimeout = suite.timeout(); - suite.timeout(5_000); + // allow to set a higher timeout for slow machines from cli flag + const warmupTimeout = Math.max(defaultTimeout, 5_000); + suite.timeout(warmupTimeout); before(async () => { const start = Date.now(); console.log('Warming up language service...'); diff --git a/packages/language-server/test/plugins/typescript/typescript-performance.test.ts b/packages/language-server/test/plugins/typescript/typescript-performance.test.ts index 13ba896da..e1bdbb7fc 100644 --- a/packages/language-server/test/plugins/typescript/typescript-performance.test.ts +++ b/packages/language-server/test/plugins/typescript/typescript-performance.test.ts @@ -33,14 +33,19 @@ describe('TypeScript Plugin Performance Tests', () => { return { plugin, document, append, prepend }; } - it('should be fast enough', async function () { + it('should be fast enough', async function() { const { document, plugin, append, prepend } = setup('performance.svelte'); + + // allow to set a higher timeout for slow machines from cli flag + const performanceTimeout = Math.max(this.timeout(), 25_000); + this.timeout(performanceTimeout); + const benchmarkElapse = Math.ceil(await benchmark()); // it usually takes around 5-6 times of the benchmark result // plus 1 for the benchmark itself const newTimeout = benchmarkElapse * 7; - if (newTimeout < this.timeout()) { + if (newTimeout < performanceTimeout) { console.log(`Benchmark took ${benchmarkElapse}ms. Setting timeout to ${newTimeout}ms`); this.timeout(newTimeout); } @@ -78,5 +83,5 @@ describe('TypeScript Plugin Performance Tests', () => { return end - start; } - }).timeout(25_000); + }); }); From 280d2f5805aa0ca3c0fe2eda0850979df1077dd8 Mon Sep 17 00:00:00 2001 From: phancb Date: Fri, 17 Nov 2023 16:38:59 +0800 Subject: [PATCH 2/3] scale cli timeout to cover previous case --- .../plugins/typescript/features/CompletionProvider.test.ts | 2 +- .../plugins/typescript/features/DiagnosticsProvider.test.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts b/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts index 8e674cde1..f79fa8b71 100644 --- a/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts @@ -1041,7 +1041,7 @@ describe('CompletionProviderImpl', function () { const item = completions?.items?.[0]; assert.strictEqual(item?.label, 'abc'); } - }); + }).timeout(this.timeout() * 2); it('provides default slot-let completion for components with type definition', async () => { const { completionProvider, document } = setup('component-events-completion-ts-def.svelte'); diff --git a/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts b/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts index 5e8810928..6aa9918bf 100644 --- a/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts @@ -55,7 +55,7 @@ describe('DiagnosticsProvider', function () { const diagnostics3 = await plugin.getDiagnostics(document); assert.deepStrictEqual(diagnostics3.length, 1); - }); + }).timeout(this.timeout() * 2.5); it('notices changes of module resolution because of new file', async () => { const { plugin, document, lsAndTsDocResolver } = setup('unresolvedimport.svelte'); @@ -90,7 +90,7 @@ describe('DiagnosticsProvider', function () { unlinkSync(newTsFilePath); unlinkSync(newFilePath); } - }); + }).timeout(this.timeout() * 2.5); it('notices update of imported module', async () => { const { plugin, document, lsAndTsDocResolver } = setup( @@ -116,7 +116,7 @@ describe('DiagnosticsProvider', function () { const diagnostics2 = await plugin.getDiagnostics(document); assert.deepStrictEqual(diagnostics2.length, 0); await lsAndTsDocResolver.deleteSnapshot(newFilePath); - }); + }).timeout(this.timeout() * 2.5); it('notices file changes in all services that reference that file', async () => { // Hacky but ensures that this tests is not interfered with by other tests From b6fa5fd2de042f8295a26f4bda14b1261faa752f Mon Sep 17 00:00:00 2001 From: phancb Date: Fri, 17 Nov 2023 18:16:27 +0800 Subject: [PATCH 3/3] set timeout before setup and benchmark --- .../test/plugins/typescript/typescript-performance.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/language-server/test/plugins/typescript/typescript-performance.test.ts b/packages/language-server/test/plugins/typescript/typescript-performance.test.ts index e1bdbb7fc..305c8fc02 100644 --- a/packages/language-server/test/plugins/typescript/typescript-performance.test.ts +++ b/packages/language-server/test/plugins/typescript/typescript-performance.test.ts @@ -33,13 +33,13 @@ describe('TypeScript Plugin Performance Tests', () => { return { plugin, document, append, prepend }; } - it('should be fast enough', async function() { - const { document, plugin, append, prepend } = setup('performance.svelte'); - + it('should be fast enough', async function () { // allow to set a higher timeout for slow machines from cli flag const performanceTimeout = Math.max(this.timeout(), 25_000); this.timeout(performanceTimeout); + const { document, plugin, append, prepend } = setup('performance.svelte'); + const benchmarkElapse = Math.ceil(await benchmark()); // it usually takes around 5-6 times of the benchmark result // plus 1 for the benchmark itself