Skip to content

Commit

Permalink
fix incorrect state after indicator cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
arksap2002 authored and Vladislav Artiukhov committed Oct 10, 2024
1 parent c1afd2b commit f05e950
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ class LLMWithFeedbackCycle(
errorMonitor,
)

// Process stopped checking
if (indicator.isCanceled()) {
executionResult = FeedbackCycleExecutionResult.CANCELED
break
}

when (response.errorCode) {
ResponseErrorCode.OK -> {
log.info { "Test suite generated successfully: ${response.testSuite!!}" }
Expand Down Expand Up @@ -264,6 +270,12 @@ class LLMWithFeedbackCycle(
// saving the compilable test cases
compilableTestCases.addAll(testCasesCompilationResult.compilableTestCases)

// Process stopped checking
if (indicator.isCanceled()) {
executionResult = FeedbackCycleExecutionResult.CANCELED
break
}

if (!testCasesCompilationResult.allTestCasesCompilable && !isLastIteration(requestsCount)) {
log.info { "Non-compilable test suite: \n${testsPresenter.representTestSuite(generatedTestSuite!!)}" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ object ToolUtils {
* @return true if the process has been stopped, false otherwise
*/
fun isProcessStopped(errorMonitor: ErrorMonitor, indicator: CustomProgressIndicator): Boolean {
return errorMonitor.hasErrorOccurred() || isProcessCanceled(indicator)
return errorMonitor.hasErrorOccurred() || isProcessCanceled(errorMonitor, indicator)
}

fun isProcessCanceled(indicator: CustomProgressIndicator): Boolean {
fun isProcessCanceled(errorMonitor: ErrorMonitor, indicator: CustomProgressIndicator): Boolean {
if (indicator.isCanceled()) {
// TODO: we must not stop this indicator! cancellation MAY imply stoppage
errorMonitor.notifyErrorOccurrence()
// TODO: we must not stop this indicator! cancellation MAY already imply stoppage
// See: https://github.com/JetBrains-Research/TestSpark/issues/375
indicator.stop()
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class OpenAIRequestManager(project: Project) : IJRequestManager(project) {
// check response
when (val responseCode = connection.responseCode) {
HttpURLConnection.HTTP_OK -> {
assembleLlmResponse(request, testsAssembler, indicator)
assembleLlmResponse(request, testsAssembler, indicator, errorMonitor)
}

HttpURLConnection.HTTP_INTERNAL_ERROR -> {
Expand Down Expand Up @@ -115,9 +115,10 @@ class OpenAIRequestManager(project: Project) : IJRequestManager(project) {
httpRequest: HttpRequests.Request,
testsAssembler: TestsAssembler,
indicator: CustomProgressIndicator,
errorMonitor: ErrorMonitor,
) {
while (true) {
if (ToolUtils.isProcessCanceled(indicator)) return
if (ToolUtils.isProcessCanceled(errorMonitor, indicator)) return

var text = httpRequest.reader.readLine()

Expand Down

0 comments on commit f05e950

Please sign in to comment.