From 071b54deb949af421e02439cc230ca0267fa3fcf Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 10 Mar 2023 16:07:51 +0100 Subject: [PATCH] Clean up mute for bunches --- .../kotlin/test/mutes/MutedTestToJson.kt | 23 ++++--------- .../kotlin/test/mutes/MutedTestsSync.kt | 32 +++++++------------ .../kotlin/test/mutes/TeamCityInteraction.kt | 15 +++++---- 3 files changed, 26 insertions(+), 44 deletions(-) diff --git a/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/MutedTestToJson.kt b/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/MutedTestToJson.kt index 1f937c51d40..5fce5c65863 100644 --- a/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/MutedTestToJson.kt +++ b/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/MutedTestToJson.kt @@ -18,12 +18,9 @@ data class MuteTestJson( val resolution: JsonNode ) -internal fun createMuteTestJson(testName: String, description: String, scopeId: String, isBuildType: Boolean): MuteTestJson { +internal fun createMuteTestJson(testName: String, description: String, scopeId: String): MuteTestJson { val assignmentJson = """{ "text" : "$TAG $description" }""" - val scopeJson = if (isBuildType) - """{"buildTypes":{"buildType":[{"id":"$scopeId"}]}}""" - else - """{"project":{"id":"$scopeId"}}""" + val scopeJson = """{"project":{"id":"$scopeId"}}""" val targetJson = """{ "tests" : { "test" : [ { "name" : "$testName" } ] } }""" val resolutionJson = """{ "type" : "manually" }""" @@ -36,17 +33,9 @@ internal fun createMuteTestJson(testName: String, description: String, scopeId: ) } -internal fun filterMutedTestsByScope(muteTestJson: List, scopeId: String, isBuildType: Boolean): Map { +internal fun filterMutedTestsByScope(muteTestJson: List, scopeId: String): Map { val filterCondition = { testJson: MuteTestJson -> - if (isBuildType) { - val buildTypes = testJson.scope.get("buildTypes") - val buildTypeIds = buildTypes?.get("buildType")?.toList()?.map { - it.get("id").textValue() - } ?: listOf() - buildTypeIds.contains(scopeId) - } else { - testJson.scope.get("project")?.get("id")?.textValue() == scopeId - } + testJson.scope.get("project")?.get("id")?.textValue() == scopeId } return muteTestJson.filter(filterCondition) @@ -59,12 +48,12 @@ internal fun filterMutedTestsByScope(muteTestJson: List, scopeId: .toMap() } -internal fun transformMutedTestsToJson(flakyTests: List?, scopeId: String, isBuildType: Boolean): Map { +internal fun transformMutedTestsToJson(flakyTests: List?, scopeId: String): Map { val mutedMap = mutableMapOf() if (flakyTests != null) { for (muted in flakyTests) { val testName = formatClassnameWithInnerClasses(muted.key) - mutedMap[testName] = createMuteTestJson(testName, muted.issue ?: "", scopeId, isBuildType) + mutedMap[testName] = createMuteTestJson(testName, muted.issue ?: "", scopeId) } } return mutedMap diff --git a/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/MutedTestsSync.kt b/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/MutedTestsSync.kt index 9084581adf4..f70c11e6293 100644 --- a/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/MutedTestsSync.kt +++ b/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/MutedTestsSync.kt @@ -33,36 +33,26 @@ private fun syncMutedTests( uploadMutedTests(uploadList) } -internal fun getMandatoryProperty(propertyName: String) = (System.getProperty(propertyName) - ?: throw Exception("Property $propertyName must be set")) +internal fun getMandatoryProperty(propertyName: String) = + System.getProperty(propertyName) ?: throw Exception("Property $propertyName must be set") -private const val mutesPackageName = "org.jetbrains.kotlin.test.mutes" -internal val projectId = getMandatoryProperty("$mutesPackageName.tests.project.id") +private const val MUTES_PACKAGE_NAME = "org.jetbrains.kotlin.test.mutes" +internal val projectId = getMandatoryProperty("$MUTES_PACKAGE_NAME.tests.project.id") class RemotelyMutedTests { - val tests = getMutedTestsOnTeamcityForRootProject(projectId) - val projectTests = getTestsJson(projectId, false) - internal fun getTestsJson(scopeId: String, isBuildType: Boolean = true): Map { - return filterMutedTestsByScope(tests, scopeId, isBuildType) + private val tests = getMutedTestsOnTeamcityForRootProject(projectId) + val projectTests = getTestsJson(projectId) + private fun getTestsJson(scopeId: String): Map { + return filterMutedTestsByScope(tests, scopeId) } } class LocallyMutedTests { - private val muteCommonTestKey = "COMMON" - val tests = getMutedTestsFromDatabase() - val projectTests = getTestsJson(muteCommonTestKey, projectId, false) + val projectTests = transformMutedTestsToJson(getCommonMuteTests(), projectId) - internal fun getTestsJson(platformId: String, scopeId: String, isBuildType: Boolean = true): Map { - return transformMutedTestsToJson(tests[platformId], scopeId, isBuildType) - } - - private fun getMutedTestsFromDatabase(): Map> { + private fun getCommonMuteTests(): List { val databaseDir = "../../../tests" - val commonDatabaseFile = File(databaseDir, "mute-common.csv") - - val mutedTestsMap = mutableMapOf>() - mutedTestsMap[muteCommonTestKey] = flakyTests(commonDatabaseFile) - return mutedTestsMap + return flakyTests(commonDatabaseFile) } } \ No newline at end of file diff --git a/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/TeamCityInteraction.kt b/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/TeamCityInteraction.kt index 00c4b869553..cd783d462d2 100644 --- a/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/TeamCityInteraction.kt +++ b/compiler/tests-mutes/tc-integration/src/org/jetbrains/kotlin/test/mutes/TeamCityInteraction.kt @@ -11,7 +11,7 @@ private val headers = mapOf("Content-type" to "application/json", "Accept" to "a private val authUser = object : Authorization { override val header = "Authorization" to "Bearer ${getMandatoryProperty("org.jetbrains.kotlin.test.mutes.teamcity.server.token")}" } -private const val requestTimeoutSec = 120.0 +private const val REQUEST_TIMEOUT_SEC = 120.0 internal fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List { @@ -29,11 +29,14 @@ internal fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List(it) } } -private fun traverseAll(requestHref: String, requestParams: Map): List { +private fun traverseAll( + @Suppress("SameParameterValue") requestHref: String, + requestParams: Map +): List { val jsonResponses = mutableListOf() fun request(url: String, params: Map): String { - val currentResponse = khttp.get(url, headers, params, auth = authUser, timeout = requestTimeoutSec) + val currentResponse = khttp.get(url, headers, params, auth = authUser, timeout = REQUEST_TIMEOUT_SEC) checkResponseAndLog(currentResponse) val currentJsonResponse = jsonObjectMapper.readTree(currentResponse.text) jsonResponses.add(currentJsonResponse) @@ -41,7 +44,7 @@ private fun traverseAll(requestHref: String, requestParams: Map) } var nextHref = request("$buildServerUrl$requestHref", requestParams) - while (!nextHref.isBlank()) { + while (nextHref.isNotBlank()) { nextHref = request("$buildServerUrl$nextHref", emptyMap()) } @@ -55,7 +58,7 @@ internal fun uploadMutedTests(uploadMap: Map) { headers = headers, data = jsonObjectMapper.writeValueAsString(muteTestJson), auth = authUser, - timeout = requestTimeoutSec + timeout = REQUEST_TIMEOUT_SEC ) checkResponseAndLog(response) } @@ -67,7 +70,7 @@ internal fun deleteMutedTests(deleteMap: Map) { "$buildServerUrl/app/rest/mutes/id:${muteTestJson.id}", headers = headers, auth = authUser, - timeout = requestTimeoutSec + timeout = REQUEST_TIMEOUT_SEC ) try { checkResponseAndLog(response)