Fixed errors reporting in tearDown in performance tests

This commit is contained in:
Vladimir Dolzhenko
2019-10-09 21:39:54 +02:00
parent 8b750bfdc7
commit e9894fb35a
6 changed files with 63 additions and 26 deletions
@@ -167,6 +167,8 @@ class Stats(
printTestFailed(stabilityName, "stability above $stabilityPercentage %") printTestFailed(stabilityName, "stability above $stabilityPercentage %")
} }
} }
} else {
printTimings(testName, printOnlyErrors = true, statInfoArray = statInfoArray)
} }
} }
@@ -180,15 +182,20 @@ class Stats(
private fun printTimings( private fun printTimings(
prefix: String, prefix: String,
statInfoArray: Array<StatInfos>, statInfoArray: Array<StatInfos>,
printOnlyErrors: Boolean = false,
attemptFn: (Int) -> String = { attempt -> "#$attempt" } attemptFn: (Int) -> String = { attempt -> "#$attempt" }
) { ) {
for (statInfoIndex in statInfoArray.withIndex()) { for (statInfoIndex in statInfoArray.withIndex()) {
val attempt = statInfoIndex.index val attempt = statInfoIndex.index
val statInfo = statInfoIndex.value ?: continue val statInfo = statInfoIndex.value ?: continue
val n = "$name: $prefix ${attemptFn(attempt)}" val n = "$name: $prefix ${attemptFn(attempt)}"
printTestStarted(n)
val t = statInfo[ERROR_KEY] as? Throwable val t = statInfo[ERROR_KEY] as? Throwable
if (t != null) printTestFinished(n, t) else { if (t != null) {
printTestStarted(n)
printTestFinished(n, t)
} else if (!printOnlyErrors) {
printTestStarted(n)
for ((k, v) in statInfo) { for ((k, v) in statInfo) {
if (k == TEST_KEY) continue if (k == TEST_KEY) continue
printStatValue("$n $k", v) printStatValue("$n $k", v)
@@ -217,6 +224,12 @@ class Stats(
if (phaseData.testName != WARM_UP) { if (phaseData.testName != WARM_UP) {
printWarmUpTimings(phaseData.testName, warmUpStatInfosArray) printWarmUpTimings(phaseData.testName, warmUpStatInfosArray)
} else {
printTimings(
phaseData.testName,
printOnlyErrors = true,
statInfoArray = warmUpStatInfosArray
) { attempt -> "warm-up #$attempt" }
} }
warmUpStatInfosArray.filterNotNull().map { it[ERROR_KEY] as? Throwable }.firstOrNull()?.let { throw it } warmUpStatInfosArray.filterNotNull().map { it[ERROR_KEY] as? Throwable }.firstOrNull()?.let { throw it }
@@ -237,7 +250,8 @@ class Stats(
val phaseProfiler = createPhaseProfiler(phaseData, phaseName, attempt) val phaseProfiler = createPhaseProfiler(phaseData, phaseName, attempt)
val setUpMillis = measureTimeMillis { phaseData.setUp(testData) } val setUpMillis = measureTimeMillis { phaseData.setUp(testData) }
logMessage { "setup took $setUpMillis ms" } val attemptName = "${phaseData.testName} #$attempt"
logMessage { "$attemptName setup took $setUpMillis ms" }
val valueMap = HashMap<String, Any>(2 * PerformanceCounter.numberOfCounters + 1) val valueMap = HashMap<String, Any>(2 * PerformanceCounter.numberOfCounters + 1)
statInfosArray[attempt] = valueMap statInfosArray[attempt] = valueMap
@@ -255,26 +269,26 @@ class Stats(
} }
} catch (t: Throwable) { } catch (t: Throwable) {
println("# error at ${phaseData.testName} #$attempt:") logMessage(t) { "error at $attemptName" }
t.printStackTrace()
valueMap[ERROR_KEY] = t valueMap[ERROR_KEY] = t
break
} finally { } finally {
try { try {
val tearDownMillis = measureTimeMillis { val tearDownMillis = measureTimeMillis {
phaseData.tearDown(testData) phaseData.tearDown(testData)
} }
logMessage { "tearDown took $tearDownMillis ms" } logMessage { "$attemptName tearDown took $tearDownMillis ms" }
} catch (t: Throwable) { } catch (t: Throwable) {
println("# error at ${phaseData.testName} #$attempt:") logMessage(t) { "error at tearDown of $attemptName" }
t.printStackTrace()
valueMap[ERROR_KEY] = t valueMap[ERROR_KEY] = t
break
} finally { } finally {
PerformanceCounter.resetAllCounters() PerformanceCounter.resetAllCounters()
} }
} }
} }
} catch (t: Throwable) { } catch (t: Throwable) {
println("error at ${phaseData.testName}:") logMessage(t) { "error at ${phaseData.testName}" }
tcPrintErrors(phaseData.testName, listOf(t)) tcPrintErrors(phaseData.testName, listOf(t))
} }
return statInfosArray return statInfosArray
@@ -356,7 +370,6 @@ class Stats(
println("error at $testName:") println("error at $testName:")
printStatValue(testName, -1) printStatValue(testName, -1)
tcPrintErrors(testName, listOf(error)) tcPrintErrors(testName, listOf(error))
//printTestFinished(testName)
} }
private fun printTestFailed(testName: String, details: String) { private fun printTestFailed(testName: String, details: String) {
@@ -376,7 +389,6 @@ class Stats(
printTestStarted(name) printTestStarted(name)
val (time, errors) = block() val (time, errors) = block()
tcPrintErrors(name, errors) tcPrintErrors(name, errors)
//printTestFinished(name, time, includeStatValue = false)
} }
private fun tcEscape(s: String) = s.replace("|", "||") private fun tcEscape(s: String) = s.replace("|", "||")
@@ -5,8 +5,6 @@
package org.jetbrains.kotlin.idea.testFramework package org.jetbrains.kotlin.idea.testFramework
import com.intellij.ide.impl.ProjectUtil
import com.intellij.openapi.externalSystem.importing.ImportSpecBuilder
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode
import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManagerImpl import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManagerImpl
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
@@ -23,19 +21,6 @@ import kotlin.test.assertNotNull
fun refreshGradleProject(projectPath: String, project: Project) { fun refreshGradleProject(projectPath: String, project: Project) {
_importProject(projectPath, project) _importProject(projectPath, project)
// val gradleArguments = System.getProperty("kotlin.test.gradle.import.arguments")
// ExternalSystemUtil.refreshProjects(
// ImportSpecBuilder(project, GradleConstants.SYSTEM_ID)
// .forceWhenUptodate()
// .useDefaultCallback()
// .use(ProgressExecutionMode.MODAL_SYNC)
// .also {
// gradleArguments?.run(it::withArguments)
// }
// )
//ProjectUtil.updateLastProjectLocation(projectPath)
dispatchAllInvocationEvents() dispatchAllInvocationEvents()
} }
@@ -22,6 +22,8 @@ import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.runInEdtAndWait import com.intellij.testFramework.runInEdtAndWait
import com.intellij.util.ui.UIUtil import com.intellij.util.ui.UIUtil
import org.jetbrains.kotlin.idea.parameterInfo.HintType import org.jetbrains.kotlin.idea.parameterInfo.HintType
import java.io.PrintWriter
import java.io.StringWriter
fun commitAllDocuments() { fun commitAllDocuments() {
val fileDocumentManager = FileDocumentManager.getInstance() val fileDocumentManager = FileDocumentManager.getInstance()
@@ -104,4 +106,12 @@ fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementatio
fun logMessage(message: () -> String) { fun logMessage(message: () -> String) {
println("-- ${message()}") println("-- ${message()}")
}
fun logMessage(t: Throwable, message: () -> String) {
val writer = StringWriter()
PrintWriter(writer).use {
t.printStackTrace(it)
}
println("-- ${message()}:\n$writer")
} }
@@ -24,6 +24,8 @@ import com.intellij.testFramework.runInEdtAndWait
import com.intellij.util.ThrowableRunnable import com.intellij.util.ThrowableRunnable
import com.intellij.util.ui.UIUtil import com.intellij.util.ui.UIUtil
import org.jetbrains.kotlin.idea.parameterInfo.HintType import org.jetbrains.kotlin.idea.parameterInfo.HintType
import java.io.PrintWriter
import java.io.StringWriter
fun commitAllDocuments() { fun commitAllDocuments() {
ProjectManagerEx.getInstanceEx().openProjects.forEach { project -> ProjectManagerEx.getInstanceEx().openProjects.forEach { project ->
@@ -89,4 +91,12 @@ fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementatio
fun logMessage(message: () -> String) { fun logMessage(message: () -> String) {
println("-- ${message()}") println("-- ${message()}")
}
fun logMessage(t: Throwable, message: () -> String) {
val writer = StringWriter()
PrintWriter(writer).use {
t.printStackTrace(it)
}
println("-- ${message()}:\n$writer")
} }
@@ -27,6 +27,8 @@ import com.intellij.util.ui.UIUtil
import org.jetbrains.kotlin.idea.parameterInfo.HintType import org.jetbrains.kotlin.idea.parameterInfo.HintType
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException import java.util.concurrent.TimeoutException
import java.io.PrintWriter
import java.io.StringWriter
fun commitAllDocuments() { fun commitAllDocuments() {
val fileDocumentManager = FileDocumentManager.getInstance() val fileDocumentManager = FileDocumentManager.getInstance()
@@ -133,4 +135,12 @@ fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementatio
fun logMessage(message: () -> String) { fun logMessage(message: () -> String) {
println("-- ${message()}") println("-- ${message()}")
}
fun logMessage(t: Throwable, message: () -> String) {
val writer = StringWriter()
PrintWriter(writer).use {
t.printStackTrace(it)
}
println("-- ${message()}:\n$writer")
} }
@@ -23,6 +23,8 @@ import com.intellij.testFramework.runInEdtAndWait
import com.intellij.util.ui.UIUtil import com.intellij.util.ui.UIUtil
import org.jetbrains.kotlin.idea.parameterInfo.HintType import org.jetbrains.kotlin.idea.parameterInfo.HintType
import java.nio.file.Paths import java.nio.file.Paths
import java.io.PrintWriter
import java.io.StringWriter
fun commitAllDocuments() { fun commitAllDocuments() {
val fileDocumentManager = FileDocumentManager.getInstance() val fileDocumentManager = FileDocumentManager.getInstance()
@@ -105,4 +107,12 @@ fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementatio
fun logMessage(message: () -> String) { fun logMessage(message: () -> String) {
println("-- ${message()}") println("-- ${message()}")
}
fun logMessage(t: Throwable, message: () -> String) {
val writer = StringWriter()
PrintWriter(writer).use {
t.printStackTrace(it)
}
println("-- ${message()}:\n$writer")
} }