[rdct-tests]: make test API agent context aware + Editors API refactoring

Huge thanks to Artem Bukhonov

GitOrigin-RevId: 7382c8773dd5f026e1ad174bb2a1d90d03c49a65
This commit is contained in:
Anastasia Katsman
2023-05-18 15:17:23 +02:00
committed by intellij-monorepo-bot
parent cf70cf6044
commit 76d092c2b2
2 changed files with 31 additions and 7 deletions

View File

@@ -9,13 +9,37 @@ import org.jetbrains.annotations.ApiStatus
/**
* Provides access to all essential entities on this agent required to perform test operations
*/
@ApiStatus.Internal
class AgentContext(
val agentId: RdAgentId,
val application: Application,
val projectOrNull: Project?,
interface AgentContext {
val agentId: RdAgentId
val application: Application
val projectOrNull: Project?
val protocol: IProtocol
) {
val project: Project
get() = projectOrNull ?: error("Project shouldn't be requested for the projectless application")
companion object {
fun create(agentId: RdAgentId,
application: Application,
projectOrNull: Project?,
protocol: IProtocol) : AgentContext {
return AgentContextImpl(agentId, application, projectOrNull, protocol)
}
}
}
@ApiStatus.Internal
interface HostContext : AgentContext
@ApiStatus.Internal
interface GatewayContext : AgentContext
@ApiStatus.Internal
interface ClientContext : AgentContext
// If you need some extra data or behavior for a particular class, e.g. HostContext should have some host specific data, just derive from
// the AgentContextImpl and derive it also from HostContext
// then create proper inheritor in AgentContext.create() depending on agentId
@ApiStatus.Internal
internal class AgentContextImpl(
override val agentId: RdAgentId,
override val application: Application,
override val projectOrNull: Project?,
override val protocol: IProtocol
) : HostContext, ClientContext, GatewayContext

View File

@@ -127,7 +127,7 @@ class DistributedTestHost {
// Execute test method
lateinit var result: RdTask<Boolean>
val context = AgentContext(session.agentId, application, projectOrNull, protocol)
val context = AgentContext.create(session.agentId, application, projectOrNull, protocol)
logger.info("'$actionTitle': starting action")
val elapsedAction = measureTimeMillis {
result = action.action.invoke(context)