Traverse all pages of muted tests on Teamcity (KTI-326)

incomplete list of remotely muted tests was causing re-muting of tests
that were not fetched
This commit is contained in:
Yunir Salimzyanov
2020-08-26 14:37:58 +03:00
parent 06a592c018
commit e12c35de5f
@@ -1,5 +1,6 @@
package org.jetbrains.kotlin.test.mutes
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.module.kotlin.treeToValue
import khttp.DEFAULT_TIMEOUT
import khttp.responses.Response
@@ -14,20 +15,39 @@ private val authUser = object : Authorization {
internal fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List<MuteTestJson> {
val params = mapOf(
val requestHref = "/app/rest/mutes"
val requestParams = mapOf(
"locator" to "project:(id:$rootScopeId)",
"fields" to "mute(id,assignment(text),scope(project(id),buildTypes(buildType(id))),target(tests(test(name))),resolution)"
"fields" to "mute(id,assignment(text),scope(project(id),buildTypes(buildType(id))),target(tests(test(name))),resolution),nextHref"
)
val jsonResponses = traverseAll(requestHref, requestParams)
val response = khttp.get("$buildServerUrl/app/rest/mutes", headers, params, auth = authUser)
checkResponseAndLog(response)
val alreadyMutedTestsOnTeamCity = jsonObjectMapper.readTree(response.text).get("mute")
.filter { jn -> jn.get("assignment").get("text").textValue().startsWith(TAG) }
val alreadyMutedTestsOnTeamCity = jsonResponses.flatMap {
it.get("mute").filter { jn -> jn.get("assignment").get("text").textValue().startsWith(TAG) }
}
return alreadyMutedTestsOnTeamCity.mapNotNull { jsonObjectMapper.treeToValue<MuteTestJson>(it) }
}
private fun traverseAll(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)
checkResponseAndLog(currentResponse)
val currentJsonResponse = jsonObjectMapper.readTree(currentResponse.text)
jsonResponses.add(currentJsonResponse)
return currentJsonResponse.get("nextHref")?.textValue() ?: ""
}
var nextHref = request("$buildServerUrl$requestHref", requestParams)
while (!nextHref.isBlank()) {
nextHref = request("$buildServerUrl$nextHref", emptyMap())
}
return jsonResponses
}
internal fun uploadMutedTests(uploadMap: Map<String, MuteTestJson>) {
for ((_, muteTestJson) in uploadMap) {
val response = khttp.post(