From 571b296f860cb11b732b384a2ce54e6a4426dae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Andr=C3=A9s=20Chaparro=20Quintero?= <62714297+PedroChaparro@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:00:18 -0500 Subject: [PATCH] fix(java-runner): Update execution time limit (#15) * fix(java-runner): Increase tests execution time limit * fix(java-runner): Handle empty error message --- .../implementations/java-tests-runner.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/infrastructure/implementations/java-tests-runner.go b/src/infrastructure/implementations/java-tests-runner.go index 81a2321..6cf6796 100644 --- a/src/infrastructure/implementations/java-tests-runner.go +++ b/src/infrastructure/implementations/java-tests-runner.go @@ -21,6 +21,8 @@ var templateArchivePathTemplate = "%s/template.zip" var testsArchivePathTemplate = "%s/tests.zip" var submissionArchivePathTemplate = "%s/submission.zip" +var defaultErrorLineOnEmptyErrorLines = "[ERROR] We had an error while running the tests. It's possible that the tests execution time exceeded our limit. Please try again or report the issue if it persists." + // SaveArchivesInFS saves the archives needed to run the tests in the file system func (javaTestsRunner *JavaTestsRunner) SaveArchivesInFS(dto *dtos.TestArchivesDTO) error { // Ensure the directory doesn't exist @@ -188,7 +190,13 @@ func (javaTestsRunner *JavaTestsRunner) deleteArchives(submissionUUID string) er // RunTests runs the tests and returns the result func (javaTestsRunner *JavaTestsRunner) RunTests(submissionUUID string) (dto *dtos.TestResultDTO, err error) { - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + timeLimitInMinutes := 2.0 + timeLimitInSeconds := int(timeLimitInMinutes * 60) + + ctx, cancel := context.WithTimeout( + context.Background(), + time.Duration(timeLimitInSeconds)*time.Second, + ) defer cancel() // Delete the submission directory at the end @@ -203,8 +211,9 @@ func (javaTestsRunner *JavaTestsRunner) RunTests(submissionUUID string) (dto *dt // Prepare the command testAndBuildCommand := fmt.Sprintf( - "cd %s && timeout 1m mvn clean test", + "cd %s && timeout %dm mvn clean test", submissionPath, + timeLimitInSeconds, ) cmd := exec.CommandContext( @@ -222,6 +231,10 @@ func (javaTestsRunner *JavaTestsRunner) RunTests(submissionUUID string) (dto *dt errorLines := javaTestsRunner.getErrorLinesFromOutput(string(out)) errorLines = javaTestsRunner.sanitizeConsoleTextLines(errorLines) + if len(errorLines) == 0 { + errorLines = []string{defaultErrorLineOnEmptyErrorLines} + } + return &dtos.TestResultDTO{ SubmissionUUID: submissionUUID, TestsPassed: false,