Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ nativeAgentLibName = drill-agent
nativeAgentHookEnabled = false
macosLd64 = false

org.gradle.jvmargs = -Xmx4096m -XX:MaxPermSize=1024m
org.gradle.jvmargs = -Xmx4096m
org.gradle.daemon = false
org.gradle.parallel = true
org.gradle.workers.max = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ object ParameterDefinitions: AgentParameterDefinitionCollection() {
val RECOMMENDED_TESTS_TARGET_BUILD_VERSION = AgentParameterDefinition.forString(name = "recommendedTestsTargetBuildVersion", defaultValue = "").register()
val RECOMMENDED_TESTS_BASELINE_COMMIT_SHA = AgentParameterDefinition.forString(name = "recommendedTestsBaselineCommitSha", defaultValue = "").register()
val RECOMMENDED_TESTS_BASELINE_BUILD_VERSION = AgentParameterDefinition.forString(name = "recommendedTestsBaselineBuildVersion", defaultValue = "").register()
val RECOMMENDED_TESTS_LIMIT = AgentParameterDefinition.forInt(name = "recommendedTestsLimit", defaultValue = 1000).register()
val RECOMMENDED_TESTS_FILE = NullableAgentParameterDefinition.forString(
name = "recommendedTestsFile",
description = "Path to a JSON file containing a list of tests to skip."
).register()

val TEST_TRACING_PER_SESSION_ENABLED = AgentParameterDefinition.forBoolean(name = "testTracingPerTestSessionEnabled", defaultValue = true).register()
val TEST_TRACING_PER_TEST_LAUNCH_ENABLED = AgentParameterDefinition.forBoolean(name = "testTracingPerTestLaunchEnabled", defaultValue = true).register()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ actual object JUnitPlatformPrioritizingTransformer : Transformer, AbstractJUnitT
cc
)
)
// JUnit Platform 1.11+ added getOutputDirectoryProvider() to LauncherDiscoveryRequest.
// This ensures compatibility with both JUnit Platform < 1.11 and >= 1.11.
val runtimeClassLoader = classLoader ?: ClassLoader.getSystemClassLoader()
runCatching {
runtimeClassLoader.loadClass(LauncherDiscoveryRequest)
.getMethod("getOutputDirectoryProvider")
}.onSuccess { method ->
val returnType = method.returnType.name
cc.addMethod(
CtMethod.make(
"""
public $returnType getOutputDirectoryProvider() {
return delegate.getOutputDirectoryProvider();
}
""".trimIndent(),
cc
)
)
logger.debug { "JUnit Platform >= 1.11 detected: added getOutputDirectoryProvider() delegation (returnType=$returnType) to LauncherDiscoveryRequestAdapter" }
}.onFailure {
logger.debug { "JUnit Platform < 1.11 detected: skipping getOutputDirectoryProvider() delegation" }
}
cc.toClass(classLoader, protectionDomain)
return cc
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import com.epam.drill.agent.test.execution.TestExecutionRecorder
import com.epam.drill.agent.test.execution.TestMethodInfo
import com.epam.drill.agent.transport.MetricsMessageReceiver
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import java.io.File

interface RecommendedTestsReceiver {
fun getTestsToSkip(): List<TestMethodInfo>
Expand All @@ -39,10 +42,13 @@ class RecommendedTestsReceiverImpl(
private val logger = KotlinLogging.logger {}

override fun getTestsToSkip(): List<TestMethodInfo> {
val testsToSkipFilePath = Configuration.parameters[ParameterDefinitions.RECOMMENDED_TESTS_FILE]
if (testsToSkipFilePath != null) {
return loadTestsToSkipFromFile(testsToSkipFilePath)
}
if (!Configuration.parameters[ParameterDefinitions.RECOMMENDED_TESTS_ENABLED])
return emptyList()
val groupId = Configuration.parameters[DefaultParameterDefinitions.GROUP_ID]
val testTaskId = Configuration.parameters[ParameterDefinitions.TEST_TASK_ID]
val targetAppId = Configuration.parameters[ParameterDefinitions.RECOMMENDED_TESTS_TARGET_APP_ID]
val targetBuildVersion = Configuration.parameters[ParameterDefinitions.RECOMMENDED_TESTS_TARGET_BUILD_VERSION]
.takeIf { it.isNotEmpty() }
Expand All @@ -53,26 +59,30 @@ class RecommendedTestsReceiverImpl(
val baselineBuildVersion =
Configuration.parameters[ParameterDefinitions.RECOMMENDED_TESTS_BASELINE_BUILD_VERSION]
.takeIf { it.isNotEmpty() }

val limit = Configuration.parameters[ParameterDefinitions.RECOMMENDED_TESTS_LIMIT]
val parameters: String = buildString {
append("?groupId=$groupId")
append("&appId=$targetAppId")
append("&testTaskId=$testTaskId")
append("&testsToSkip=true")
targetBuildVersion?.let { append("&targetBuildVersion=$it") }
targetCommitSha?.let { append("&targetCommitSha=$it") }
targetBuildVersion?.let { append("&buildVersion=$it") }
targetCommitSha?.let { append("&commitSha=$it") }
baselineCommitSha?.let { append("&baselineCommitSha=$it") }
baselineBuildVersion?.let { append("&baselineBuildVersion=$it") }
append("&impactStatuses=NOT_IMPACTED")
append("&pageSize=$limit")
}
logger.debug { "Retrieving information about recommended tests, testTaskId: $testTaskId" }
logger.debug { "Retrieving information about recommended tests..." }
return runCatching {
agentMessageReceiver.receive(
val response = agentMessageReceiver.receive(
AgentMessageDestination(
"GET",
"/recommended-tests$parameters",
"/impacted-tests$parameters",
),
RecommendedTestsApiResponse::class
).data.recommendedTests.map { it.toTestMethodInfo() }
)
if (response.paging.pageSize >= limit) {
logger.warn { "The number of recommended tests is more or equal than $limit. Consider increasing the limit." }
}
response.data.map { it.toTestMethodInfo() }
}.onFailure {
logger.warn { "Unable to retrieve information about recommended tests. Error message: $it" }
}.getOrElse {
Expand All @@ -83,16 +93,29 @@ class RecommendedTestsReceiverImpl(
override fun sendSkippedTest(test: TestMethodInfo) {
testExecutionRecorder.recordTestIgnoring(test, isSmartSkip = true)
}

private fun loadTestsToSkipFromFile(filePath: String): List<TestMethodInfo> {
logger.debug { "Loading tests to skip from file: $filePath" }
return runCatching {
val content = File(filePath).readText()
val entries = fileJson.decodeFromString(ListSerializer(TestDefinitionResponse.serializer()), content)
entries.map { it.toTestMethodInfo() }.also {
logger.info { "Loaded ${it.size} tests to skip from file: $filePath" }
}
}.onFailure {
logger.warn { "Unable to load tests to skip from file '$filePath'. Error message: $it" }
}.getOrElse {
emptyList()
}
}
}

@Serializable
class RecommendedTestsApiResponse(
val data: RecommendedTestsResponse
)
private val fileJson = Json { ignoreUnknownKeys = true }

@Serializable
class RecommendedTestsResponse(
val recommendedTests: List<TestDefinitionResponse>
class RecommendedTestsApiResponse(
val data: List<TestDefinitionResponse>,
val paging: Paging
)

@Serializable
Expand All @@ -103,6 +126,14 @@ class TestDefinitionResponse(
val testName: String,
val tags: List<String>,
val metadata: Map<String, String>,
val impactStatus: String,
)

@Serializable
data class Paging(
val page: Int,
val pageSize: Int,
val total: Long?
)

private fun TestDefinitionResponse.toTestMethodInfo() = TestMethodInfo(
Expand Down
Loading