mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IJPL-160418 Fix flaky test RestartOfBackendRobotUiTest.gw deploy and restart of backend part 2
Provide CoroutineScope instead of CoroutineContext in KernelService to ensure that services which use Kernel will depend on this scope. GitOrigin-RevId: b33a4a059dce0ac0669f7192b2fcefd6d3963858
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a4effe8aa5
commit
609a61704d
@@ -15,19 +15,18 @@ import fleet.kernel.transactor
|
||||
import fleet.rpc.remoteApiDescriptor
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
@Service
|
||||
private class RemoteKernelScopeHolder(private val coroutineScope: CoroutineScope) {
|
||||
private class RemoteKernelScopeHolder {
|
||||
|
||||
suspend fun createRemoteKernel(): RemoteKernel {
|
||||
val kernelService = KernelService.instance
|
||||
val kernelCoroutineContext = kernelService.kernelCoroutineContext.await()
|
||||
val kernelScope = kernelService.kernelCoroutineScope.await()
|
||||
val kernelCoroutineContext = kernelScope.coroutineContext.kernelCoroutineContext()
|
||||
return RemoteKernelImpl(
|
||||
kernelCoroutineContext.transactor,
|
||||
coroutineScope.childScope("RemoteKernelScope", kernelCoroutineContext),
|
||||
kernelScope.childScope("RemoteKernelScope", kernelCoroutineContext),
|
||||
CommonInstructionSet.decoder(),
|
||||
KernelRpcSerialization,
|
||||
)
|
||||
@@ -46,7 +45,7 @@ internal class RemoteKernelProvider : RemoteApiProvider {
|
||||
|
||||
internal class BackendKernelService(coroutineScope: CoroutineScope) : KernelService {
|
||||
|
||||
override val kernelCoroutineContext: CompletableDeferred<CoroutineContext> = CompletableDeferred()
|
||||
override val kernelCoroutineScope: CompletableDeferred<CoroutineScope> = CompletableDeferred()
|
||||
|
||||
init {
|
||||
coroutineScope.launch {
|
||||
@@ -55,7 +54,7 @@ internal class BackendKernelService(coroutineScope: CoroutineScope) : KernelServ
|
||||
initWorkspaceClock()
|
||||
}
|
||||
handleEntityTypes(transactor(), this)
|
||||
kernelCoroutineContext.complete(currentCoroutineContext().kernelCoroutineContext())
|
||||
kernelCoroutineScope.complete(this)
|
||||
updateDbInTheEventDispatchThread()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
package com.intellij.platform.kernel
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
/**
|
||||
* Don't use directly. Use [withKernel] instead.
|
||||
*/
|
||||
interface KernelService {
|
||||
|
||||
val kernelCoroutineContext: Deferred<CoroutineContext>
|
||||
val kernelCoroutineScope: Deferred<CoroutineScope>
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.platform.kernel
|
||||
|
||||
import com.intellij.platform.kernel.util.kernelCoroutineContext
|
||||
import com.intellij.platform.util.coroutines.attachAsChildTo
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
/**
|
||||
* Entry point to operations which work with the kernel.
|
||||
@@ -14,13 +14,10 @@ import kotlin.coroutines.CoroutineContext
|
||||
* i.e., once the kernel is added to all coroutines by default.
|
||||
*/
|
||||
suspend fun <T> withKernel(action: suspend CoroutineScope.() -> T): T {
|
||||
val kernelContext = kernelCoroutineContext()
|
||||
return withContext(kernelContext, action)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private fun kernelCoroutineContext(): CoroutineContext {
|
||||
return KernelService.instance
|
||||
.kernelCoroutineContext
|
||||
.getCompleted()
|
||||
val kernelScope = KernelService.instance.kernelCoroutineScope.await()
|
||||
val kernelContext = kernelScope.coroutineContext.kernelCoroutineContext()
|
||||
return withContext(kernelContext) {
|
||||
attachAsChildTo(kernelScope)
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@ internal class KernelApplicationInitializedListener : ApplicationInitializedList
|
||||
|
||||
override suspend fun execute() {
|
||||
val service = ApplicationManager.getApplication().serviceAsync<KernelService>()
|
||||
service.kernelCoroutineContext.join()
|
||||
service.kernelCoroutineScope.join()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user