Do not invalidate package caches on generic events, KT-25264

This commit is contained in:
Vladimir Dolzhenko
2019-07-17 17:18:10 +02:00
parent 3e9765f5bb
commit 022275b781
15 changed files with 145 additions and 62 deletions
@@ -22,7 +22,7 @@ import org.junit.AfterClass
import java.io.File
/**
* inspired by @see AbstractCompletionHandlerTest
* inspired by @see AbstractCompletionHandlerTests
*/
abstract class AbstractPerformanceCompletionHandlerTests(
private val defaultCompletionType: CompletionType,
@@ -34,6 +34,7 @@ abstract class AbstractPerformanceCompletionHandlerTests(
private val ELEMENT_TEXT_PREFIX = "ELEMENT_TEXT:"
private val TAIL_TEXT_PREFIX = "TAIL_TEXT:"
private val COMPLETION_CHAR_PREFIX = "CHAR:"
private val COMPLETION_CHARS_PREFIX = "CHARS:"
private val CODE_STYLE_SETTING_PREFIX = "CODE_STYLE_SETTING:"
companion object {
@@ -74,12 +75,10 @@ abstract class AbstractPerformanceCompletionHandlerTests(
val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX)
val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX)
val completionCharString = InTextDirectivesUtils.findStringWithPrefixes(fileText, COMPLETION_CHAR_PREFIX)
val completionChar = when(completionCharString) {
"\\n", null -> '\n'
"\\t" -> '\t'
else -> completionCharString.singleOrNull() ?: error("Incorrect completion char: \"$completionCharString\"")
}
val completionChars = completionChars(
char = InTextDirectivesUtils.findStringWithPrefixes(fileText, COMPLETION_CHAR_PREFIX),
chars = InTextDirectivesUtils.findStringWithPrefixes(fileText, COMPLETION_CHARS_PREFIX)
)
val completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType
@@ -102,7 +101,7 @@ abstract class AbstractPerformanceCompletionHandlerTests(
}
doPerfTestWithTextLoaded(
testPath, completionType, invocationCount, lookupString, itemText, tailText, completionChar
testPath, completionType, invocationCount, lookupString, itemText, tailText, completionChars
)
} finally {
if (configured) {
@@ -120,7 +119,7 @@ abstract class AbstractPerformanceCompletionHandlerTests(
lookupString: String?,
itemText: String?,
tailText: String?,
completionChar: Char
completionChars: String
) {
val testName = getTestName(false)
@@ -132,7 +131,7 @@ abstract class AbstractPerformanceCompletionHandlerTests(
setUpFixture(testPath)
},
test = {
perfTestCore(completionType, time, lookupString, itemText, tailText, completionChar)
perfTestCore(completionType, time, lookupString, itemText, tailText, completionChars)
},
tearDown = {
runWriteAction {
@@ -147,14 +146,20 @@ abstract class AbstractPerformanceCompletionHandlerTests(
lookupString: String?,
itemText: String?,
tailText: String?,
completionChar: Char
completionChars: String
) {
completionChars?.let {
for (idx in 0 until it.length - 1) {
fixture.type(it[idx])
}
}
fixture.complete(completionType, time)
if (lookupString != null || itemText != null || tailText != null) {
val item = getExistentLookupElement(lookupString, itemText, tailText)
if (item != null) {
selectItem(item, completionChar)
selectItem(item, completionChars.last())
}
}
}
@@ -103,6 +103,16 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
}
}
protected fun warmUpProject(stats: Stats) {
val project = innerPerfOpenProject("helloKotlin", stats, "warm-up")
try {
val perfHighlightFile = perfHighlightFile(project, "src/HelloMain.kt", stats, "warm-up")
assertTrue("kotlin project has been not imported properly", perfHighlightFile.isNotEmpty())
} finally {
closeProject(project)
}
}
override fun tearDown() {
RunAll(
ThrowableRunnable { super.tearDown() },
@@ -122,6 +132,9 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
return if (lastIndexOf >= 0) fileName.substring(lastIndexOf + 1) else fileName
}
protected fun perfOpenKotlinProject(stats: Stats) =
perfOpenProject("perfTestProject", stats = stats, path = "..")
protected fun perfOpenProject(name: String, stats: Stats, path: String = "idea/testData/perfTest") {
myProject = innerPerfOpenProject(name, stats, path = path, note = "")
}
@@ -291,8 +304,8 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
stats: Stats,
note: String = ""
): List<HighlightInfo> {
var highlightInfos: List<HighlightInfo> = emptyList()
IdentifierHighlighterPassFactory.doWithHighlightingEnabled {
return highlightFile {
var highlightInfos: List<HighlightInfo> = emptyList()
stats.perfTest<EditorFile, List<HighlightInfo>>(
testName = "highlighting ${if (note.isNotEmpty()) "$note " else ""}${simpleFilename(fileName)}",
setUp = {
@@ -309,9 +322,21 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
PsiManager.getInstance(project).dropPsiCaches()
}
)
highlightInfos
}
//println("${"-".repeat(40)}\n$fileName ->\n${highlightInfos.joinToString("\n")}\n")
}
fun highlightFile(psiFile: PsiFile): List<HighlightInfo> {
return highlightFile {
highlightFile(myProject!!, psiFile)
}
}
private fun highlightFile(block: () -> List<HighlightInfo>): List<HighlightInfo> {
var highlightInfos: List<HighlightInfo> = emptyList()
IdentifierHighlighterPassFactory.doWithHighlightingEnabled {
highlightInfos = block()
}
return highlightInfos
}
@@ -392,7 +417,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
}
}
private fun openFileInEditor(project: Project, name: String): EditorFile {
fun openFileInEditor(project: Project, name: String): EditorFile {
val fileDocumentManager = FileDocumentManager.getInstance()
val fileEditorManager = FileEditorManager.getInstance(project)
@@ -421,6 +446,6 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
return virtualFile!!.toPsiFile(project)!!
}
private data class EditorFile(val psiFile: PsiFile, val document: Document)
data class EditorFile(val psiFile: PsiFile, val document: Document)
}
@@ -26,7 +26,7 @@ public class PerformanceCompletionCharFilterTestGenerated extends AbstractPerfor
}
public void testAllFilesPresentInCharFilter() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/handlers/charFilter"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/handlers/charFilter"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("Colon.kt")
@@ -144,6 +144,11 @@ public class PerformanceCompletionCharFilterTestGenerated extends AbstractPerfor
runTest("idea/idea-completion/testData/handlers/charFilter/LParenth.kt");
}
@TestMetadata("MessageBundle1.kt")
public void testMessageBundle1() throws Exception {
runTest("idea/idea-completion/testData/handlers/charFilter/MessageBundle1.kt");
}
@TestMetadata("NamedParameter1.kt")
public void testNamedParameter1() throws Exception {
runTest("idea/idea-completion/testData/handlers/charFilter/NamedParameter1.kt");
@@ -35,10 +35,7 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() {
super.setUp()
// warm up: open simple small project
if (!warmedUp) {
val project = innerPerfOpenProject("helloKotlin", hwStats, "warm-up")
val perfHighlightFile = perfHighlightFile(project, "src/HelloMain.kt", hwStats, "warm-up")
assertTrue("kotlin project has been not imported properly", perfHighlightFile.isNotEmpty())
closeProject(project)
warmUpProject(hwStats)
warmedUp = true
}
@@ -58,7 +55,7 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() {
tcSuite("Kotlin project") {
val stats = Stats("kotlin project")
stats.use {
perfOpenProject("perfTestProject", stats = it, path = "..")
perfOpenKotlinProject(it)
perfHighlightFile("compiler/psi/src/org/jetbrains/kotlin/psi/KtFile.kt", stats = it)
@@ -71,7 +68,7 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() {
tcSuite("Kotlin project highlight build gradle") {
val stats = Stats("kotlin project highlight build gradle")
stats.use {
perfOpenProject("perfTestProject", stats = it, path = "..")
perfOpenKotlinProject(it)
enableAnnotatorsAndLoadDefinitions()