From e12c35de5f9a01ac1ab90c74541332954f57c3b1 Mon Sep 17 00:00:00 2001 From: Yunir Salimzyanov Date: Wed, 26 Aug 2020 14:37:58 +0300 Subject: [PATCH] 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 --- .../kotlin/test/mutes/TeamCityInteraction.kt | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/TeamCityInteraction.kt b/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/TeamCityInteraction.kt index baa70f26cfc..bc298e46c90 100644 --- a/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/TeamCityInteraction.kt +++ b/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/TeamCityInteraction.kt @@ -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 { - 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(it) } } +private fun traverseAll(requestHref: String, requestParams: Map): List { + val jsonResponses = mutableListOf() + + fun request(url: String, params: Map): 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) { for ((_, muteTestJson) in uploadMap) { val response = khttp.post(