Skip to content

Commit c5b571c

Browse files
authored
Added division of timeout for several function (#1847)
Added division of timeout
1 parent ef1f2fd commit c5b571c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

utbot-python/src/main/kotlin/org/utbot/python/PythonTestCaseGenerator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class PythonTestCaseGenerator(
3939
private val fileOfMethod: String,
4040
private val isCancelled: () -> Boolean,
4141
private val timeoutForRun: Long = 0,
42-
private val until: Long = 0,
4342
private val sourceFileContent: String,
4443
private val mypyStorage: MypyAnnotationStorage,
4544
private val mypyReportLine: List<MypyReportLine>,
@@ -145,7 +144,7 @@ class PythonTestCaseGenerator(
145144
}.take(maxSubstitutions)
146145
}
147146

148-
fun generate(methodDescription: PythonMethodHeader): PythonTestSet {
147+
fun generate(methodDescription: PythonMethodHeader, until: Long): PythonTestSet {
149148
storageForMypyMessages.clear()
150149

151150
val typeStorage = PythonTypeStorage.get(mypyStorage)

utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationProcessor.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ object PythonTestGenerationProcessor {
9898
fileOfMethod = pythonFilePath,
9999
isCancelled = isCanceled,
100100
timeoutForRun = timeoutForRun,
101-
until = startTime + timeout,
102101
sourceFileContent = pythonFileContent,
103102
mypyStorage = mypyStorage,
104103
mypyReportLine = report,
105104
mypyConfigFile = mypyConfigFile,
106105
)
107106

108-
val tests = pythonMethods.map { method ->
109-
testCaseGenerator.generate(method)
107+
val until = startTime + timeout
108+
val tests = pythonMethods.mapIndexed { index, method ->
109+
val methodsLeft = pythonMethods.size - index
110+
val localUntil = (until - System.currentTimeMillis()) / methodsLeft + System.currentTimeMillis()
111+
testCaseGenerator.generate(method, localUntil)
110112
}
111113

112114
val (notEmptyTests, emptyTestSets) = tests.partition { it.executions.isNotEmpty() }

0 commit comments

Comments
 (0)