Skip to content

Commit

Permalink
Make sure that dumb mode does not start during RA
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 25924c1c7e23ee12f920df36fb8aca8106fde1a8
  • Loading branch information
andrei-kuznetsov authored and intellij-monorepo-bot committed Nov 19, 2024
1 parent 5d6f946 commit 3756242
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.indexing

import com.google.common.util.concurrent.SettableFuture
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.application.ReadWriteActionSupport
import com.intellij.openapi.application.readAction
import com.intellij.openapi.application.writeAction
import com.intellij.openapi.components.service
import com.intellij.openapi.fileTypes.ExtensionFileNameMatcher
Expand All @@ -23,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.testFramework.*
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.util.application
import com.intellij.util.concurrency.ThreadingAssertions
import com.intellij.util.indexing.PerProjectIndexingQueue.QueuedFiles
import com.intellij.util.indexing.diagnostic.ProjectScanningHistory
import com.intellij.util.indexing.diagnostic.ScanningType
Expand All @@ -32,6 +36,7 @@ import com.intellij.util.indexing.mocks.*
import com.intellij.util.indexing.roots.IndexableFilesIterator
import com.intellij.util.indexing.roots.kind.IndexableSetOrigin
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import org.junit.*
Expand All @@ -41,6 +46,8 @@ import org.junit.runners.JUnit4
import java.nio.file.Files
import java.nio.file.Paths
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Future
import java.util.concurrent.locks.LockSupport

@RunWith(JUnit4::class)
class UnindexedFilesScannerTest {
Expand Down Expand Up @@ -97,6 +104,33 @@ class UnindexedFilesScannerTest {
}
}

fun createSuspendedScanningTask(startTrigger: Future<*>): UnindexedFilesScanner {
return UnindexedFilesScanner(project, false, true, startTrigger, null, null, false, CompletableDeferred(ScanningIterators("test")))
}

@Test
fun `test dumb mode does not start during RA`() {
ThreadingAssertions.assertNoReadAccess()
ThreadingAssertions.assertBackgroundThread()

runBlocking(Dispatchers.IO) {
readAction {
val startTrigger = SettableFuture.create<Unit>()
try {
assertThat(application.service<ReadWriteActionSupport>().smartModeConstraint(project).isSatisfied()).isTrue()
createSuspendedScanningTask(startTrigger).queue()
repeat(100) {
LockSupport.parkNanos(100)
assertThat(application.service<ReadWriteActionSupport>().smartModeConstraint(project).isSatisfied()).isTrue()
}
}
finally {
startTrigger.set(Unit)
}
}
}
}

@Test
fun `test scanning scheduled asynchronously when writeAccessAllowed=false`() {
runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class SmartModeScheduler(private val project: Project, sc: CoroutineScope) : Dis
}

fun getCurrentMode(): Int =
(if (filesScannerExecutor.hasQueuedTasks || filesScannerExecutor.isRunning.value) SCANNING else 0) +
(if (filesScannerExecutor.isRunning.value) SCANNING else 0) +
(if (projectDumbState.value.isDumb) DUMB else 0)

fun clear() {
Expand Down

0 comments on commit 3756242

Please sign in to comment.