[Tests] Ensure the temporary directories are cleared
This change may prevent OOMs. Context: https://jetbrains.slack.com/archives/C4U955N6B/p1685000899030279
This commit is contained in:
committed by
Space Team
parent
039b5fca7a
commit
46ea908daf
+18
-1
@@ -37,8 +37,10 @@ import org.jetbrains.kotlin.test.model.ResultingArtifact
|
||||
import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest
|
||||
import org.jetbrains.kotlin.test.services.*
|
||||
import org.jetbrains.kotlin.test.services.impl.TemporaryDirectoryManagerImpl
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.TestInfo
|
||||
import java.io.IOException
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.exists
|
||||
@@ -52,7 +54,13 @@ abstract class AbstractAnalysisApiBasedTest : TestWithDisposable() {
|
||||
protected lateinit var testDataPath: Path
|
||||
private set
|
||||
|
||||
private lateinit var testServices: TestServices
|
||||
private var _testServices: TestServices? = null
|
||||
|
||||
private var testServices: TestServices
|
||||
get() = _testServices ?: error("`_testServices` has not been initialized")
|
||||
set(value) {
|
||||
_testServices = value
|
||||
}
|
||||
|
||||
protected open fun configureTest(builder: TestConfigurationBuilder) {
|
||||
configurator.configureTest(builder, disposable)
|
||||
@@ -148,6 +156,15 @@ abstract class AbstractAnalysisApiBasedTest : TestWithDisposable() {
|
||||
doTestByModuleStructure(moduleStructure, testServices)
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun cleanupTemporaryDirectories() {
|
||||
try {
|
||||
_testServices?.temporaryDirectoryManager?.cleanupTemporaryDirectories()
|
||||
} catch (e: IOException) {
|
||||
println("Failed to clean temporary directories: ${e.message}\n${e.stackTrace}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun createTestConfiguration(): TestConfiguration {
|
||||
val testConfiguration = testConfiguration(testDataPath.toString(), configure)
|
||||
Disposer.register(disposable, testConfiguration.rootDisposable)
|
||||
|
||||
Reference in New Issue
Block a user