Skip to content

Commit 174077f

Browse files
authored
fix: race condition in step functions language server activation test (aws#5244)
### Problem: Sometimes the language server can start and fire the onReady event before we are listening for it in the tests, causing the tests to never receive the event ### Solution: Set isReady on the ASLLanguageClient class and wait for the client to be ready in the test
1 parent 8aad058 commit 174077f

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

packages/core/src/stepFunctions/asl/client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
TextEdit,
2727
window,
2828
workspace,
29-
EventEmitter,
3029
} from 'vscode'
3130

3231
import {
@@ -53,8 +52,7 @@ interface Settings {
5352
}
5453

5554
export class ASLLanguageClient {
56-
private static ASLInit = new EventEmitter<void>()
57-
static onASLInit = this.ASLInit.event
55+
static isReady = false
5856

5957
/**
6058
* Starts the ASL LSP client/server and creates related resources (vscode `OutputChannel`,
@@ -173,7 +171,7 @@ export class ASLLanguageClient {
173171
`${message}\nUse setting 'aws.stepfunctions.asl.maxItemsComputed' to configure the limit.`
174172
)
175173
})
176-
this.ASLInit.fire()
174+
this.isReady = true
177175
})
178176
}
179177
}

packages/core/src/testInteg/stepFunctions/init.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import assert from 'assert'
77
import { createTestWorkspaceFolder, openATextEditorWithText } from '../../test/testUtil'
88
import vscode from 'vscode'
99
import { ASLLanguageClient } from '../../stepFunctions/asl/client'
10+
import { waitUntil } from '../../shared'
1011

1112
describe('stepFunctions ASL LSP', async function () {
1213
let tempFolder: string
@@ -23,10 +24,9 @@ describe('stepFunctions ASL LSP', async function () {
2324
}`
2425
const fileName = 'stepfunction.asl'
2526
const editor = await openATextEditorWithText(stateMachineFileText, fileName, tempFolder)
26-
await new Promise(resolve => {
27-
ASLLanguageClient.onASLInit(() => {
28-
resolve(undefined)
29-
})
27+
await waitUntil(async () => ASLLanguageClient.isReady, {
28+
timeout: 30000,
29+
interval: 500,
3030
})
3131
const result = (await vscode.commands.executeCommand(
3232
'vscode.executeCompletionItemProvider',

0 commit comments

Comments
 (0)