Skip to content

Commit 65a933e

Browse files
committed
chore: do not use coroutines apis for containerized LSP init healthcheck
1 parent ea42384 commit 65a933e

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
package lsp.utils
22

3-
import kotlinx.coroutines.delay
4-
import kotlinx.coroutines.runBlocking
5-
import kotlinx.coroutines.withTimeoutOrNull
63
import completions.lsp.client.KotlinLspClient
74
import completions.lsp.client.LspConnectionManager
5+
import java.util.concurrent.TimeUnit
6+
import java.util.concurrent.TimeoutException
87
import kotlin.time.Duration.Companion.milliseconds
9-
import kotlin.time.Duration.Companion.seconds
108

119
object LspIntegrationTestUtils {
1210
const val DEFAULT_LSP_HOST = "localhost"
1311
const val DEFAULT_LSP_PORT = 9999
1412

15-
fun waitForLspReady(host: String = DEFAULT_LSP_HOST, port: Int = DEFAULT_LSP_PORT, workspace: String) =
16-
runBlocking {
17-
var lastError: Throwable? = null
18-
var attempt = 0
19-
withTimeoutOrNull(90.seconds) {
20-
while (true) {
21-
try {
22-
KotlinLspClient(host, port).use { client ->
23-
client.initRequest(workspace, projectName = "probe").join()
24-
}
25-
return@withTimeoutOrNull
26-
} catch (t: Throwable) {
27-
lastError = t
28-
delay(LspConnectionManager.exponentialBackoffMillis(attempt++).milliseconds)
29-
}
13+
fun waitForLspReady(host: String = DEFAULT_LSP_HOST, port: Int = DEFAULT_LSP_PORT, workspace: String) {
14+
var lastError: Throwable?
15+
var attempt = 0
16+
while (true) {
17+
try {
18+
KotlinLspClient(host, port).use { client ->
19+
client.initRequest(workspace, projectName = "probe").get(90, TimeUnit.SECONDS)
3020
}
31-
} ?: error("LSP server did not become ready in time: ${lastError?.message}")
21+
return
22+
} catch (t: Throwable) {
23+
lastError = t
24+
if (t is TimeoutException) error("LSP server never started: $lastError")
25+
Thread.sleep(LspConnectionManager.exponentialBackoffMillis(attempt++).milliseconds.inWholeMilliseconds)
26+
}
3227
}
28+
}
3329
}

0 commit comments

Comments
 (0)