Skip to content

Commit b58860c

Browse files
committed
fix context management
1 parent ce4c909 commit b58860c

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ enum class Tool {
139139
classFqn: String
140140
) {
141141
val classStats: StatsForClass = try {
142-
withUtContext(UtContext(project.classloader)) {
142+
withUtContext(ContextManager.createNewContext(project.classloader)) {
143143
runGeneration(
144144
project.name,
145145
cut,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.utbot.contest
2+
3+
import kotlinx.coroutines.cancel
4+
import kotlinx.coroutines.cancelChildren
5+
import org.utbot.framework.plugin.api.util.UtContext
6+
7+
object ContextManager {
8+
private val currentContexts = mutableListOf<UtContext>()
9+
10+
fun createNewContext(classLoader: ClassLoader) =
11+
UtContext(classLoader).apply {
12+
currentContexts.add(this)
13+
}
14+
15+
fun cancelAll() {
16+
currentContexts.forEach {
17+
it.cancelChildren()
18+
it.cancel()
19+
}
20+
currentContexts.clear()
21+
}
22+
23+
}

utbot-junit-contest/src/main/kotlin/org/utbot/monitoring/StatisticsMonitoring.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.utbot.common.ThreadBasedExecutor
1414
import org.utbot.common.bracket
1515
import org.utbot.common.info
1616
import org.utbot.contest.ContestEstimatorJdkInfoProvider
17+
import org.utbot.contest.ContextManager
1718
import org.utbot.contest.GlobalStats
1819
import org.utbot.contest.Paths
1920
import org.utbot.contest.Tool
@@ -76,8 +77,7 @@ fun main(args: Array<String>) {
7677

7778
}
7879

79-
utContext.cancelChildren()
80-
utContext.cancel()
80+
ContextManager.cancelAll()
8181
ConcreteExecutor.defaultPool.forceTerminateProcesses()
8282
System.gc()
8383
}

0 commit comments

Comments
 (0)