Clean up mute for bunches
This commit is contained in:
committed by
Space Team
parent
e42e2b28db
commit
071b54deb9
+6
-17
@@ -18,12 +18,9 @@ data class MuteTestJson(
|
|||||||
val resolution: JsonNode
|
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 assignmentJson = """{ "text" : "$TAG $description" }"""
|
||||||
val scopeJson = if (isBuildType)
|
val scopeJson = """{"project":{"id":"$scopeId"}}"""
|
||||||
"""{"buildTypes":{"buildType":[{"id":"$scopeId"}]}}"""
|
|
||||||
else
|
|
||||||
"""{"project":{"id":"$scopeId"}}"""
|
|
||||||
val targetJson = """{ "tests" : { "test" : [ { "name" : "$testName" } ] } }"""
|
val targetJson = """{ "tests" : { "test" : [ { "name" : "$testName" } ] } }"""
|
||||||
val resolutionJson = """{ "type" : "manually" }"""
|
val resolutionJson = """{ "type" : "manually" }"""
|
||||||
|
|
||||||
@@ -36,17 +33,9 @@ internal fun createMuteTestJson(testName: String, description: String, scopeId:
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun filterMutedTestsByScope(muteTestJson: List<MuteTestJson>, scopeId: String, isBuildType: Boolean): Map<String, MuteTestJson> {
|
internal fun filterMutedTestsByScope(muteTestJson: List<MuteTestJson>, scopeId: String): Map<String, MuteTestJson> {
|
||||||
val filterCondition = { testJson: MuteTestJson ->
|
val filterCondition = { testJson: MuteTestJson ->
|
||||||
if (isBuildType) {
|
testJson.scope.get("project")?.get("id")?.textValue() == scopeId
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return muteTestJson.filter(filterCondition)
|
return muteTestJson.filter(filterCondition)
|
||||||
@@ -59,12 +48,12 @@ internal fun filterMutedTestsByScope(muteTestJson: List<MuteTestJson>, scopeId:
|
|||||||
.toMap()
|
.toMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun transformMutedTestsToJson(flakyTests: List<MutedTest>?, scopeId: String, isBuildType: Boolean): Map<String, MuteTestJson> {
|
internal fun transformMutedTestsToJson(flakyTests: List<MutedTest>?, scopeId: String): Map<String, MuteTestJson> {
|
||||||
val mutedMap = mutableMapOf<String, MuteTestJson>()
|
val mutedMap = mutableMapOf<String, MuteTestJson>()
|
||||||
if (flakyTests != null) {
|
if (flakyTests != null) {
|
||||||
for (muted in flakyTests) {
|
for (muted in flakyTests) {
|
||||||
val testName = formatClassnameWithInnerClasses(muted.key)
|
val testName = formatClassnameWithInnerClasses(muted.key)
|
||||||
mutedMap[testName] = createMuteTestJson(testName, muted.issue ?: "", scopeId, isBuildType)
|
mutedMap[testName] = createMuteTestJson(testName, muted.issue ?: "", scopeId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mutedMap
|
return mutedMap
|
||||||
|
|||||||
+11
-21
@@ -33,36 +33,26 @@ private fun syncMutedTests(
|
|||||||
uploadMutedTests(uploadList)
|
uploadMutedTests(uploadList)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun getMandatoryProperty(propertyName: String) = (System.getProperty(propertyName)
|
internal fun getMandatoryProperty(propertyName: String) =
|
||||||
?: throw Exception("Property $propertyName must be set"))
|
System.getProperty(propertyName) ?: throw Exception("Property $propertyName must be set")
|
||||||
|
|
||||||
private const val mutesPackageName = "org.jetbrains.kotlin.test.mutes"
|
private const val MUTES_PACKAGE_NAME = "org.jetbrains.kotlin.test.mutes"
|
||||||
internal val projectId = getMandatoryProperty("$mutesPackageName.tests.project.id")
|
internal val projectId = getMandatoryProperty("$MUTES_PACKAGE_NAME.tests.project.id")
|
||||||
|
|
||||||
class RemotelyMutedTests {
|
class RemotelyMutedTests {
|
||||||
val tests = getMutedTestsOnTeamcityForRootProject(projectId)
|
private val tests = getMutedTestsOnTeamcityForRootProject(projectId)
|
||||||
val projectTests = getTestsJson(projectId, false)
|
val projectTests = getTestsJson(projectId)
|
||||||
internal fun getTestsJson(scopeId: String, isBuildType: Boolean = true): Map<String, MuteTestJson> {
|
private fun getTestsJson(scopeId: String): Map<String, MuteTestJson> {
|
||||||
return filterMutedTestsByScope(tests, scopeId, isBuildType)
|
return filterMutedTestsByScope(tests, scopeId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocallyMutedTests {
|
class LocallyMutedTests {
|
||||||
private val muteCommonTestKey = "COMMON"
|
val projectTests = transformMutedTestsToJson(getCommonMuteTests(), projectId)
|
||||||
val tests = getMutedTestsFromDatabase()
|
|
||||||
val projectTests = getTestsJson(muteCommonTestKey, projectId, false)
|
|
||||||
|
|
||||||
internal fun getTestsJson(platformId: String, scopeId: String, isBuildType: Boolean = true): Map<String, MuteTestJson> {
|
private fun getCommonMuteTests(): List<MutedTest> {
|
||||||
return transformMutedTestsToJson(tests[platformId], scopeId, isBuildType)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getMutedTestsFromDatabase(): Map<String, List<MutedTest>> {
|
|
||||||
val databaseDir = "../../../tests"
|
val databaseDir = "../../../tests"
|
||||||
|
|
||||||
val commonDatabaseFile = File(databaseDir, "mute-common.csv")
|
val commonDatabaseFile = File(databaseDir, "mute-common.csv")
|
||||||
|
return flakyTests(commonDatabaseFile)
|
||||||
val mutedTestsMap = mutableMapOf<String, List<MutedTest>>()
|
|
||||||
mutedTestsMap[muteCommonTestKey] = flakyTests(commonDatabaseFile)
|
|
||||||
return mutedTestsMap
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+9
-6
@@ -11,7 +11,7 @@ private val headers = mapOf("Content-type" to "application/json", "Accept" to "a
|
|||||||
private val authUser = object : Authorization {
|
private val authUser = object : Authorization {
|
||||||
override val header = "Authorization" to "Bearer ${getMandatoryProperty("org.jetbrains.kotlin.test.mutes.teamcity.server.token")}"
|
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<MuteTestJson> {
|
internal fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List<MuteTestJson> {
|
||||||
@@ -29,11 +29,14 @@ internal fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List<Mu
|
|||||||
return alreadyMutedTestsOnTeamCity.mapNotNull { jsonObjectMapper.treeToValue<MuteTestJson>(it) }
|
return alreadyMutedTestsOnTeamCity.mapNotNull { jsonObjectMapper.treeToValue<MuteTestJson>(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun traverseAll(requestHref: String, requestParams: Map<String, String>): List<JsonNode> {
|
private fun traverseAll(
|
||||||
|
@Suppress("SameParameterValue") requestHref: String,
|
||||||
|
requestParams: Map<String, String>
|
||||||
|
): List<JsonNode> {
|
||||||
val jsonResponses = mutableListOf<JsonNode>()
|
val jsonResponses = mutableListOf<JsonNode>()
|
||||||
|
|
||||||
fun request(url: String, params: Map<String, String>): String {
|
fun request(url: String, params: Map<String, String>): 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)
|
checkResponseAndLog(currentResponse)
|
||||||
val currentJsonResponse = jsonObjectMapper.readTree(currentResponse.text)
|
val currentJsonResponse = jsonObjectMapper.readTree(currentResponse.text)
|
||||||
jsonResponses.add(currentJsonResponse)
|
jsonResponses.add(currentJsonResponse)
|
||||||
@@ -41,7 +44,7 @@ private fun traverseAll(requestHref: String, requestParams: Map<String, String>)
|
|||||||
}
|
}
|
||||||
|
|
||||||
var nextHref = request("$buildServerUrl$requestHref", requestParams)
|
var nextHref = request("$buildServerUrl$requestHref", requestParams)
|
||||||
while (!nextHref.isBlank()) {
|
while (nextHref.isNotBlank()) {
|
||||||
nextHref = request("$buildServerUrl$nextHref", emptyMap())
|
nextHref = request("$buildServerUrl$nextHref", emptyMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +58,7 @@ internal fun uploadMutedTests(uploadMap: Map<String, MuteTestJson>) {
|
|||||||
headers = headers,
|
headers = headers,
|
||||||
data = jsonObjectMapper.writeValueAsString(muteTestJson),
|
data = jsonObjectMapper.writeValueAsString(muteTestJson),
|
||||||
auth = authUser,
|
auth = authUser,
|
||||||
timeout = requestTimeoutSec
|
timeout = REQUEST_TIMEOUT_SEC
|
||||||
)
|
)
|
||||||
checkResponseAndLog(response)
|
checkResponseAndLog(response)
|
||||||
}
|
}
|
||||||
@@ -67,7 +70,7 @@ internal fun deleteMutedTests(deleteMap: Map<String, MuteTestJson>) {
|
|||||||
"$buildServerUrl/app/rest/mutes/id:${muteTestJson.id}",
|
"$buildServerUrl/app/rest/mutes/id:${muteTestJson.id}",
|
||||||
headers = headers,
|
headers = headers,
|
||||||
auth = authUser,
|
auth = authUser,
|
||||||
timeout = requestTimeoutSec
|
timeout = REQUEST_TIMEOUT_SEC
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
checkResponseAndLog(response)
|
checkResponseAndLog(response)
|
||||||
|
|||||||
Reference in New Issue
Block a user