11package org .jetbrains .plugins .scala .compiler
22
3+ import com .intellij .openapi .application .ApplicationManager
34import com .intellij .openapi .externalSystem .model .ProjectSystemId
45import com .intellij .openapi .module .Module
56import com .intellij .openapi .projectRoots .{ProjectJdkTable , Sdk }
67import com .intellij .openapi .roots .{CompilerModuleExtension , ModuleRootManager }
78import com .intellij .openapi .vfs .VfsUtil
89import com .intellij .platform .externalSystem .testFramework .ExternalSystemImportingTestCase
910import com .intellij .testFramework .CompilerTester
11+ import com .intellij .testFramework .common .ThreadLeakTracker
1012import org .jetbrains .annotations .Nullable
1113import org .jetbrains .plugins .scala .base .libraryLoaders .SmartJDKLoader
1214import org .jetbrains .plugins .scala .extensions .inWriteAction
@@ -50,6 +52,8 @@ abstract class SbtProjectCompilationTestBase(separateProdAndTestSources: Boolean
5052
5153 override def getTestsTempDir : String = this .getClass.getSimpleName
5254
55+ protected def reuseCompileServerProcessBetweenTests : Boolean = true
56+
5357 override def setUp (): Unit = {
5458 super .setUp()
5559
@@ -63,10 +67,26 @@ abstract class SbtProjectCompilationTestBase(separateProdAndTestSources: Boolean
6367 }
6468
6569 SbtCachesSetupUtil .setupCoursierAndIvyCache(getProject)
70+
71+ if (reuseCompileServerProcessBetweenTests) {
72+ // noinspection ApiStatus,UnstableApiUsage
73+ ThreadLeakTracker .longRunningThreadCreated(
74+ ApplicationManager .getApplication,
75+ " BaseDataReader: output stream of scalaCompileServer" ,
76+ " BaseDataReader: error stream of scalaCompileServer" ,
77+ " scalaCompileServer"
78+ )
79+ } else {
80+ // We don't want to reuse the compile server in this test class, but it may have already been started.
81+ // We should shut it down first.
82+ CompileServerLauncher .stopServerAndWait()
83+ }
6684 }
6785
6886 override def tearDown (): Unit = try {
69- CompileServerLauncher .stopServerAndWait()
87+ if (! reuseCompileServerProcessBetweenTests) {
88+ CompileServerLauncher .stopServerAndWait()
89+ }
7090 compiler.tearDown()
7191 val settings = ScalaCompileServerSettings .getInstance()
7292 settings.USE_DEFAULT_SDK = true
0 commit comments