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
|
||||
)
|
||||
|
||||
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<MuteTestJson>, scopeId: String, isBuildType: Boolean): Map<String, MuteTestJson> {
|
||||
internal fun filterMutedTestsByScope(muteTestJson: List<MuteTestJson>, scopeId: String): Map<String, MuteTestJson> {
|
||||
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<MuteTestJson>, scopeId:
|
||||
.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>()
|
||||
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
|
||||
|
||||
+11
-21
@@ -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<String, MuteTestJson> {
|
||||
return filterMutedTestsByScope(tests, scopeId, isBuildType)
|
||||
private val tests = getMutedTestsOnTeamcityForRootProject(projectId)
|
||||
val projectTests = getTestsJson(projectId)
|
||||
private fun getTestsJson(scopeId: String): Map<String, MuteTestJson> {
|
||||
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<String, MuteTestJson> {
|
||||
return transformMutedTestsToJson(tests[platformId], scopeId, isBuildType)
|
||||
}
|
||||
|
||||
private fun getMutedTestsFromDatabase(): Map<String, List<MutedTest>> {
|
||||
private fun getCommonMuteTests(): List<MutedTest> {
|
||||
val databaseDir = "../../../tests"
|
||||
|
||||
val commonDatabaseFile = File(databaseDir, "mute-common.csv")
|
||||
|
||||
val mutedTestsMap = mutableMapOf<String, List<MutedTest>>()
|
||||
mutedTestsMap[muteCommonTestKey] = flakyTests(commonDatabaseFile)
|
||||
return mutedTestsMap
|
||||
return flakyTests(commonDatabaseFile)
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -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<MuteTestJson> {
|
||||
@@ -29,11 +29,14 @@ internal fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List<Mu
|
||||
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>()
|
||||
|
||||
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)
|
||||
val currentJsonResponse = jsonObjectMapper.readTree(currentResponse.text)
|
||||
jsonResponses.add(currentJsonResponse)
|
||||
@@ -41,7 +44,7 @@ private fun traverseAll(requestHref: String, requestParams: Map<String, String>)
|
||||
}
|
||||
|
||||
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<String, MuteTestJson>) {
|
||||
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<String, MuteTestJson>) {
|
||||
"$buildServerUrl/app/rest/mutes/id:${muteTestJson.id}",
|
||||
headers = headers,
|
||||
auth = authUser,
|
||||
timeout = requestTimeoutSec
|
||||
timeout = REQUEST_TIMEOUT_SEC
|
||||
)
|
||||
try {
|
||||
checkResponseAndLog(response)
|
||||
|
||||
Reference in New Issue
Block a user