[Build] Update dependencies in test-mutes module
^KTI-1342
This commit is contained in:
committed by
Space Team
parent
a03f65e06b
commit
62a6bb1a31
@@ -5,10 +5,12 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api(kotlinStdlib())
|
implementation(kotlinStdlib("jdk8"))
|
||||||
implementation(project(":compiler:tests-mutes"))
|
implementation(project(":compiler:tests-mutes"))
|
||||||
implementation("khttp:khttp:1.0.0")
|
implementation(libs.ktor.client.cio)
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.0")
|
implementation(libs.ktor.client.content.negotiation)
|
||||||
|
implementation(libs.ktor.serialization.jackson)
|
||||||
|
implementation(libs.jackson.module.kotlin)
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
+6
-5
@@ -5,9 +5,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.test.mutes
|
package org.jetbrains.kotlin.test.mutes
|
||||||
|
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun main() {
|
suspend fun main() {
|
||||||
syncMutedTestsOnTeamCityWithDatabase()
|
syncMutedTestsOnTeamCityWithDatabase()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,16 +17,16 @@ fun main() {
|
|||||||
*
|
*
|
||||||
* Purpose: possibility to run flaky tests on teamcity that will not affect on build status
|
* Purpose: possibility to run flaky tests on teamcity that will not affect on build status
|
||||||
*/
|
*/
|
||||||
fun syncMutedTestsOnTeamCityWithDatabase() {
|
suspend fun syncMutedTestsOnTeamCityWithDatabase() {
|
||||||
val remotelyMutedTests = RemotelyMutedTests()
|
val remotelyMutedTests = RemotelyMutedTests()
|
||||||
val locallyMutedTests = LocallyMutedTests()
|
val locallyMutedTests = LocallyMutedTests()
|
||||||
|
|
||||||
syncMutedTests(remotelyMutedTests.projectTests, locallyMutedTests.projectTests)
|
syncMutedTests(remotelyMutedTests.projectTests, locallyMutedTests.projectTests)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun syncMutedTests(
|
private suspend fun syncMutedTests(
|
||||||
remotelyMutedTests: Map<String, MuteTestJson>,
|
remotelyMutedTests: Map<String, MuteTestJson>,
|
||||||
locallyMutedTests: Map<String, MuteTestJson>
|
locallyMutedTests: Map<String, MuteTestJson>,
|
||||||
) {
|
) {
|
||||||
val deleteList = remotelyMutedTests - locallyMutedTests.keys
|
val deleteList = remotelyMutedTests - locallyMutedTests.keys
|
||||||
val uploadList = locallyMutedTests - remotelyMutedTests.keys
|
val uploadList = locallyMutedTests - remotelyMutedTests.keys
|
||||||
@@ -40,7 +41,7 @@ private const val MUTES_PACKAGE_NAME = "org.jetbrains.kotlin.test.mutes"
|
|||||||
internal val projectId = getMandatoryProperty("$MUTES_PACKAGE_NAME.tests.project.id")
|
internal val projectId = getMandatoryProperty("$MUTES_PACKAGE_NAME.tests.project.id")
|
||||||
|
|
||||||
class RemotelyMutedTests {
|
class RemotelyMutedTests {
|
||||||
private val tests = getMutedTestsOnTeamcityForRootProject(projectId)
|
private val tests = runBlocking { getMutedTestsOnTeamcityForRootProject(projectId) }
|
||||||
val projectTests = getTestsJson(projectId)
|
val projectTests = getTestsJson(projectId)
|
||||||
private fun getTestsJson(scopeId: String): Map<String, MuteTestJson> {
|
private fun getTestsJson(scopeId: String): Map<String, MuteTestJson> {
|
||||||
return filterMutedTestsByScope(tests, scopeId)
|
return filterMutedTestsByScope(tests, scopeId)
|
||||||
|
|||||||
+51
-31
@@ -2,19 +2,37 @@ package org.jetbrains.kotlin.test.mutes
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode
|
import com.fasterxml.jackson.databind.JsonNode
|
||||||
import com.fasterxml.jackson.module.kotlin.treeToValue
|
import com.fasterxml.jackson.module.kotlin.treeToValue
|
||||||
import khttp.responses.Response
|
import io.ktor.client.*
|
||||||
import khttp.structures.authorization.Authorization
|
import io.ktor.client.plugins.*
|
||||||
|
import io.ktor.client.plugins.contentnegotiation.*
|
||||||
|
import io.ktor.client.request.*
|
||||||
|
import io.ktor.client.statement.*
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.serialization.jackson.*
|
||||||
|
import kotlin.time.DurationUnit
|
||||||
|
import kotlin.time.toDuration
|
||||||
|
|
||||||
internal const val TAG = "[MUTED-BY-CSVFILE]"
|
internal const val TAG = "[MUTED-BY-CSVFILE]"
|
||||||
private val buildServerUrl = getMandatoryProperty("org.jetbrains.kotlin.test.mutes.teamcity.server.url")
|
private val buildServerUrl = getMandatoryProperty("org.jetbrains.kotlin.test.mutes.teamcity.server.url")
|
||||||
private val headers = mapOf("Content-type" to "application/json", "Accept" to "application/json")
|
private val token = getMandatoryProperty("org.jetbrains.kotlin.test.mutes.teamcity.server.token")
|
||||||
private val authUser = object : Authorization {
|
private val REQUEST_TIMEOUT = 120.toDuration(DurationUnit.SECONDS)
|
||||||
override val header = "Authorization" to "Bearer ${getMandatoryProperty("org.jetbrains.kotlin.test.mutes.teamcity.server.token")}"
|
|
||||||
|
private val httpClient = HttpClient {
|
||||||
|
install(HttpTimeout)
|
||||||
|
install(ContentNegotiation) {
|
||||||
|
jackson()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private const val REQUEST_TIMEOUT_SEC = 120.0
|
|
||||||
|
|
||||||
|
private fun HttpRequestBuilder.applyCommonProperties() {
|
||||||
|
headers {
|
||||||
|
bearerAuth(token)
|
||||||
|
append(HttpHeaders.Accept, "application/json")
|
||||||
|
}
|
||||||
|
timeout { requestTimeoutMillis = REQUEST_TIMEOUT.inWholeMilliseconds }
|
||||||
|
}
|
||||||
|
|
||||||
internal fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List<MuteTestJson> {
|
internal suspend fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List<MuteTestJson> {
|
||||||
val requestHref = "/app/rest/mutes"
|
val requestHref = "/app/rest/mutes"
|
||||||
val requestParams = mapOf(
|
val requestParams = mapOf(
|
||||||
"locator" to "project:(id:$rootScopeId)",
|
"locator" to "project:(id:$rootScopeId)",
|
||||||
@@ -29,16 +47,23 @@ internal fun getMutedTestsOnTeamcityForRootProject(rootScopeId: String): List<Mu
|
|||||||
return alreadyMutedTestsOnTeamCity.mapNotNull { jsonObjectMapper.treeToValue<MuteTestJson>(it) }
|
return alreadyMutedTestsOnTeamCity.mapNotNull { jsonObjectMapper.treeToValue<MuteTestJson>(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun traverseAll(
|
private suspend fun traverseAll(
|
||||||
@Suppress("SameParameterValue") requestHref: String,
|
@Suppress("SameParameterValue") requestHref: String,
|
||||||
requestParams: Map<String, String>
|
requestParams: Map<String, String>,
|
||||||
): List<JsonNode> {
|
): List<JsonNode> {
|
||||||
val jsonResponses = mutableListOf<JsonNode>()
|
val jsonResponses = mutableListOf<JsonNode>()
|
||||||
|
|
||||||
fun request(url: String, params: Map<String, String>): String {
|
suspend fun request(url: String, params: Map<String, String>): String {
|
||||||
val currentResponse = khttp.get(url, headers, params, auth = authUser, timeout = REQUEST_TIMEOUT_SEC)
|
val currentResponse = httpClient.get(url) {
|
||||||
|
applyCommonProperties()
|
||||||
|
url {
|
||||||
|
for (entry in params) {
|
||||||
|
parameters.append(entry.key, entry.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
checkResponseAndLog(currentResponse)
|
checkResponseAndLog(currentResponse)
|
||||||
val currentJsonResponse = jsonObjectMapper.readTree(currentResponse.text)
|
val currentJsonResponse = jsonObjectMapper.readTree(currentResponse.bodyAsText())
|
||||||
jsonResponses.add(currentJsonResponse)
|
jsonResponses.add(currentJsonResponse)
|
||||||
return currentJsonResponse.get("nextHref")?.textValue() ?: ""
|
return currentJsonResponse.get("nextHref")?.textValue() ?: ""
|
||||||
}
|
}
|
||||||
@@ -51,27 +76,22 @@ private fun traverseAll(
|
|||||||
return jsonResponses
|
return jsonResponses
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun uploadMutedTests(uploadMap: Map<String, MuteTestJson>) {
|
internal suspend fun uploadMutedTests(uploadMap: Map<String, MuteTestJson>) {
|
||||||
for ((_, muteTestJson) in uploadMap) {
|
for ((_, muteTestJson) in uploadMap) {
|
||||||
val response = khttp.post(
|
val response = httpClient.post("$buildServerUrl/app/rest/mutes") {
|
||||||
"$buildServerUrl/app/rest/mutes",
|
applyCommonProperties()
|
||||||
headers = headers,
|
contentType(ContentType.Application.Json)
|
||||||
data = jsonObjectMapper.writeValueAsString(muteTestJson),
|
setBody(muteTestJson)
|
||||||
auth = authUser,
|
}
|
||||||
timeout = REQUEST_TIMEOUT_SEC
|
|
||||||
)
|
|
||||||
checkResponseAndLog(response)
|
checkResponseAndLog(response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun deleteMutedTests(deleteMap: Map<String, MuteTestJson>) {
|
internal suspend fun deleteMutedTests(deleteMap: Map<String, MuteTestJson>) {
|
||||||
for ((_, muteTestJson) in deleteMap) {
|
for ((_, muteTestJson) in deleteMap) {
|
||||||
val response = khttp.delete(
|
val response = httpClient.delete("$buildServerUrl/app/rest/mutes/id:${muteTestJson.id}") {
|
||||||
"$buildServerUrl/app/rest/mutes/id:${muteTestJson.id}",
|
applyCommonProperties()
|
||||||
headers = headers,
|
}
|
||||||
auth = authUser,
|
|
||||||
timeout = REQUEST_TIMEOUT_SEC
|
|
||||||
)
|
|
||||||
try {
|
try {
|
||||||
checkResponseAndLog(response)
|
checkResponseAndLog(response)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -80,13 +100,13 @@ internal fun deleteMutedTests(deleteMap: Map<String, MuteTestJson>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkResponseAndLog(response: Response) {
|
private suspend fun checkResponseAndLog(response: HttpResponse) {
|
||||||
val isResponseBad = response.connection.responseCode !in 200..299
|
val isResponseBad = response.status.value !in 200..299
|
||||||
if (isResponseBad) {
|
if (isResponseBad) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"${response.request.method}-request to ${response.request.url} failed:\n" +
|
"${response.request.method}-request to ${response.request.url} failed:\n" +
|
||||||
"${response.text}\n" +
|
"${response.bodyAsText()}\n" +
|
||||||
"${response.request.data ?: ""}"
|
"${response.request.content}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ kotlinx-metadataJvm = "0.6.2"
|
|||||||
# Forcing gson version because of https://github.com/google/gson/pull/1991
|
# Forcing gson version because of https://github.com/google/gson/pull/1991
|
||||||
gson = { strictly = "2.8.9" } # should be in sync with version.properties
|
gson = { strictly = "2.8.9" } # should be in sync with version.properties
|
||||||
jetbrains-ideaExt = "1.0.1"
|
jetbrains-ideaExt = "1.0.1"
|
||||||
|
jackson = "2.15.2"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
dexMemberList = { module = "com.jakewharton.dex:dex-member-list", version.ref = "dexMemberList" }
|
dexMemberList = { module = "com.jakewharton.dex:dex-member-list", version.ref = "dexMemberList" }
|
||||||
@@ -31,6 +32,9 @@ spdx-gradlePlugin = { module = "org.spdx:spdx-gradle-plugin", version.ref = "spd
|
|||||||
proguard-gradlePlugin = { module = "net.sf.proguard:proguard-gradle", version.ref = "proguard" }
|
proguard-gradlePlugin = { module = "net.sf.proguard:proguard-gradle", version.ref = "proguard" }
|
||||||
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
|
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
|
||||||
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
|
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
|
||||||
|
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
|
||||||
|
ktor-serialization-jackson = { module = "io.ktor:ktor-serialization-jackson", version.ref = "ktor" }
|
||||||
|
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
|
||||||
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
|
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
|
||||||
jetbrains-ideaExt-gradlePlugin = { module = "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext", version.ref = "jetbrains-ideaExt" }
|
jetbrains-ideaExt-gradlePlugin = { module = "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext", version.ref = "jetbrains-ideaExt" }
|
||||||
jdom2 = { module = "org.jdom:jdom2", version.ref = "jdom2" }
|
jdom2 = { module = "org.jdom:jdom2", version.ref = "jdom2" }
|
||||||
|
|||||||
Reference in New Issue
Block a user