Refactoring related to reviews/107679/timeline

GitOrigin-RevId: c658413f2a4e818d30a0675919373a0e48345d95
This commit is contained in:
Alexey Kryuchkov
2023-05-23 00:27:37 +04:00
committed by intellij-monorepo-bot
parent 282124defe
commit 0671d6a2d5
10 changed files with 66 additions and 34 deletions

View File

@@ -19,6 +19,5 @@
<orderEntry type="module" module-name="intellij.platform.diagnostic.telemetry.impl" />
<orderEntry type="module" module-name="intellij.java.psi" />
<orderEntry type="module" module-name="intellij.java.impl" />
<orderEntry type="module" module-name="intellij.platform.vcs.impl" />
</component>
</module>

View File

@@ -5,14 +5,12 @@ import com.intellij.core.JavaPsiBundle.message
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.ui.playback.PlaybackContext
import com.intellij.openapi.vcs.VcsConfiguration
import com.intellij.openapi.vcs.VcsShowConfirmationOption
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx
import com.intellij.platform.diagnostic.telemetry.impl.useWithScope
import com.intellij.psi.JavaDirectoryService
import com.intellij.psi.impl.file.PsiJavaDirectoryFactory
import com.jetbrains.performancePlugin.PerformanceTestSpan
import com.jetbrains.performancePlugin.commands.PerformanceCommandCoroutineAdapter
import com.jetbrains.performancePlugin.utils.VcsTestUtil
import io.opentelemetry.context.Context
/**
@@ -47,10 +45,7 @@ class CreateJavaFileCommand(text: String, line: Int) : PerformanceCommandCorouti
if (templateName == null) throw RuntimeException("File type must be one of '${POSSIBLE_FILE_TYPES.keys}'")
//Disable vcs dialog which appears on adding new file to the project tree
ProjectLevelVcsManagerEx
.getInstanceEx(context.project)
.getConfirmation(VcsConfiguration.StandardConfirmation.ADD)
.value = VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY
VcsTestUtil.provisionVcsAddFileConfirmation(context.project, VcsTestUtil.VcsAddFileConfirmation.DO_NOTHING)
ApplicationManager.getApplication().invokeAndWait(Context.current().wrap(Runnable {
PerformanceTestSpan.TRACER.spanBuilder(NAME).useWithScope {

View File

@@ -25,6 +25,5 @@
<orderEntry type="module" module-name="kotlin.base.util" />
<orderEntry type="module" module-name="intellij.platform.diagnostic.telemetry" />
<orderEntry type="module" module-name="intellij.platform.diagnostic.telemetry.impl" />
<orderEntry type="module" module-name="intellij.platform.vcs.impl" />
</component>
</module>

View File

@@ -6,15 +6,13 @@ import com.intellij.ide.fileTemplates.FileTemplateManager
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.ui.playback.PlaybackContext
import com.intellij.openapi.vcs.VcsConfiguration
import com.intellij.openapi.vcs.VcsShowConfirmationOption
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx
import com.intellij.openapi.vfs.findFileOrDirectory
import com.intellij.platform.diagnostic.telemetry.impl.useWithScope
import com.intellij.psi.impl.PsiManagerImpl
import com.intellij.psi.impl.file.PsiDirectoryImpl
import com.jetbrains.performancePlugin.PerformanceTestSpan
import com.jetbrains.performancePlugin.commands.PerformanceCommandCoroutineAdapter
import com.jetbrains.performancePlugin.utils.VcsTestUtil
import io.opentelemetry.context.Context
/**
@@ -52,10 +50,7 @@ class CreateKotlinFileCommand(text: String, line: Int) : PerformanceCommandCorou
val template = FileTemplateManager.getInstance(directory.project).getInternalTemplate(templateName)
//Disable vcs dialog which appears on adding new file to the project tree
ProjectLevelVcsManagerEx
.getInstanceEx(context.project)
.getConfirmation(VcsConfiguration.StandardConfirmation.ADD)
.value = VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY
VcsTestUtil.provisionVcsAddFileConfirmation(context.project, VcsTestUtil.VcsAddFileConfirmation.DO_NOTHING)
ApplicationManager.getApplication().invokeAndWait(Context.current().wrap(Runnable {
PerformanceTestSpan.TRACER.spanBuilder(NAME).useWithScope {

View File

@@ -46,6 +46,7 @@
<orderEntry type="module" module-name="intellij.platform.diagnostic.telemetry.impl" />
<orderEntry type="module" module-name="intellij.platform.vcs.log.impl" />
<orderEntry type="module" module-name="intellij.platform.vcs.log" />
<orderEntry type="module" module-name="intellij.platform.vcs.impl" />
<orderEntry type="module" module-name="intellij.platform.ide.impl" />
<orderEntry type="library" name="fastutil-min" level="project" />
<orderEntry type="module" module-name="intellij.platform.debugger" />

View File

@@ -8,7 +8,7 @@ import com.intellij.workspaceModel.ide.JpsProjectLoadedListener
import com.intellij.workspaceModel.ide.JpsProjectLoadedListener.Companion.LOADED
import com.intellij.workspaceModel.ide.JpsProjectLoadingManager
import com.intellij.workspaceModel.ide.impl.JpsProjectLoadingManagerImpl
import com.jetbrains.performancePlugin.utils.TimeArgumentHelper
import com.jetbrains.performancePlugin.utils.TimeArgumentParserUtil
import kotlinx.coroutines.CompletableDeferred
import java.time.temporal.ChronoUnit
@@ -41,7 +41,7 @@ class WaitJpsBuildCommand(text: String, line: Int) : PerformanceCommandCoroutine
}
})
Waiter.wait(waitTimeout, chronoUnit, "Jps project wasn't loaded in $waitTimeout ${chronoUnit.name}") {
Waiter.waitOrThrow(waitTimeout, chronoUnit, "Jps project wasn't loaded in $waitTimeout ${chronoUnit.name}") {
completableDeferred.await()
}
}
@@ -54,7 +54,7 @@ class WaitJpsBuildCommand(text: String, line: Int) : PerformanceCommandCoroutine
}
override suspend fun doExecute(context: PlaybackContext) {
val (timeout, timeunit) = TimeArgumentHelper.parse(extractCommandArgument(PREFIX))
val (timeout, timeunit) = TimeArgumentParserUtil.parse(extractCommandArgument(PREFIX))
waitJpsProjectLoaded(context.project, timeout, timeunit)
}

View File

@@ -4,7 +4,7 @@ import com.intellij.openapi.ui.playback.PlaybackContext
import com.intellij.vcs.log.data.index.VcsLogModifiableIndex
import com.intellij.vcs.log.data.index.needIndexing
import com.intellij.vcs.log.impl.VcsProjectLog.Companion.getInstance
import com.jetbrains.performancePlugin.utils.TimeArgumentHelper
import com.jetbrains.performancePlugin.utils.TimeArgumentParserUtil
import kotlinx.coroutines.CompletableDeferred
/**
@@ -23,13 +23,21 @@ class WaitVcsLogIndexingCommand(text: String, line: Int) : PerformanceCommandCor
val vcsIndex = dataManager.index as VcsLogModifiableIndex
if (vcsIndex.needIndexing()) {
val (timeout, timeunit) = TimeArgumentHelper.parse(extractCommandArgument(PREFIX))
val args = extractCommandArgument(PREFIX);
val isIndexingCompleted = CompletableDeferred<Boolean>()
vcsIndex.addListener { _ -> isIndexingCompleted.complete(true) }
Waiter.wait(timeout, timeunit, "Git log indexing project wasn't finished in $timeout $timeunit") {
//Will wait infinitely while test execution timeout won't be occurred
if (args.isBlank()) {
isIndexingCompleted.await()
}
//Will wait for specified condition and fail with exception in case when condition wasn't satisfied
else {
val (timeout, timeunit) = TimeArgumentParserUtil.parse(args)
Waiter.waitOrThrow(timeout, timeunit, "Git log indexing project wasn't finished in $timeout $timeunit") {
isIndexingCompleted.await()
}
}
}
}

View File

@@ -17,12 +17,13 @@ object Waiter {
fun checkCondition(function: BooleanSupplier): CountDownLatch {
val latch = CountDownLatch(1)
val executor: ScheduledExecutorService = ConcurrencyUtil.newSingleScheduledThreadExecutor("Performance plugin waiter")
executor.scheduleWithFixedDelay({
if (function.asBoolean) {
latch.countDown()
executor.shutdown()
}
}, 0, DELAY, TimeUnit.MILLISECONDS)
executor.scheduleWithFixedDelay(
{
if (function.asBoolean) {
latch.countDown()
executor.shutdown()
}
}, 0, DELAY, TimeUnit.MILLISECONDS)
return latch
}
@@ -34,13 +35,18 @@ object Waiter {
* @throws RuntimeException if condition of @waitLogic didn't return any value
*/
@JvmStatic
suspend fun <T> wait(timeout: Long, timeunit: TemporalUnit, errorText: String? = null, waitLogic: suspend CoroutineScope.() -> T): T? {
if (timeout > 0) {
return withTimeoutOrNull(Duration.of(timeout, timeunit), waitLogic)
?: throw RuntimeException(errorText ?: "Condition wasn't satisfied in $timeout $timeunit")
suspend fun <T> waitOrThrow(
timeout: Long,
timeunit: TemporalUnit,
errorText: String? = null,
waitLogic: suspend CoroutineScope.() -> T
): T? {
return if (timeout > 0) {
withTimeoutOrNull(Duration.of(timeout, timeunit), waitLogic)
?: throw RuntimeException(errorText ?: "Condition wasn't satisfied in $timeout $timeunit")
}
else {
return null
null
}
}

View File

@@ -6,7 +6,7 @@ import java.time.temporal.ChronoUnit
* Helper will assist you to parse time and timeunit for yours test command
* Supported units - 'ms' for millis, 's' for second, 'm' for minutes
*/
class TimeArgumentHelper {
class TimeArgumentParserUtil {
companion object {
private val ARGS_PATTERN = Regex("^([0-9]*)(ms|s|m)\$")

View File

@@ -0,0 +1,29 @@
package com.jetbrains.performancePlugin.utils
import com.intellij.openapi.project.Project
import com.intellij.openapi.vcs.VcsConfiguration
import com.intellij.openapi.vcs.VcsShowConfirmationOption
import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx
object VcsTestUtil {
@JvmStatic
fun provisionVcsAddFileConfirmation(project: Project, fileConfirmation: VcsAddFileConfirmation) {
val addFileConfirmationSetting = ProjectLevelVcsManagerEx
.getInstanceEx(project)
.getConfirmation(VcsConfiguration.StandardConfirmation.ADD)
when (fileConfirmation) {
VcsAddFileConfirmation.ADD -> addFileConfirmationSetting.value = VcsShowConfirmationOption.Value.SHOW_CONFIRMATION
VcsAddFileConfirmation.DO_NOTHING -> addFileConfirmationSetting.value = VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY
VcsAddFileConfirmation.DO_SILENTLY -> VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY
}
}
enum class VcsAddFileConfirmation {
ADD,
DO_NOTHING,
DO_SILENTLY
}
}