From f1a49df626fa28f1c2c441e1309287bf7ec57e32 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Thu, 12 Dec 2024 13:59:31 +0000 Subject: [PATCH] Fix checking TEST_PREMATURE_EXIT_FILE --- .../lib/exec/StandaloneTestStrategy.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java index b5f4ba2b4bb73f..5a8ae2fa53e54b 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java @@ -655,25 +655,7 @@ private TestAttemptResult runTestAttempt( try { spawnResults = resolver.exec(spawn, actionExecutionContext.withFileOutErr(fileOutErr)); testResultDataBuilder = TestResultData.newBuilder(); - if (actionExecutionContext - .getPathResolver() - .convertPath(resolvedPaths.getExitSafeFile()) - .exists()) { - testResultDataBuilder - .setCachable(false) - .setTestPassed(false) - .setStatus(BlazeTestStatus.FAILED); - fileOutErr - .getErrorStream() - .write( - "-- Test exited prematurely (TEST_PREMATURE_EXIT_FILE exists) --\n" - .getBytes(StandardCharsets.UTF_8)); - } else { - testResultDataBuilder - .setCachable(true) - .setTestPassed(true) - .setStatus(BlazeTestStatus.PASSED); - } + testResultDataBuilder.setCachable(true).setTestPassed(true).setStatus(BlazeTestStatus.PASSED); } catch (SpawnExecException e) { if (e.isCatastrophic()) { closeSuppressed(e, streamed); @@ -699,6 +681,22 @@ private TestAttemptResult runTestAttempt( } long endTimeMillis = actionExecutionContext.getClock().currentTimeMillis(); + // Check TEST_PREMATURE_EXIT_FILE file (and always delete it) + if (actionExecutionContext + .getPathResolver() + .convertPath(resolvedPaths.getExitSafeFile()) + .delete() && testResultDataBuilder.getTestPassed()) { + testResultDataBuilder + .setCachable(false) + .setTestPassed(false) + .setStatus(BlazeTestStatus.FAILED); + fileOutErr + .getErrorStream() + .write( + "-- Test exited prematurely (TEST_PREMATURE_EXIT_FILE exists) --\n" + .getBytes(StandardCharsets.UTF_8)); + } + // Do not override a more informative test failure with a generic failure due to the missing // shard file, which may have been caused by the test failing before the runner had a chance to // touch the file