diff options
author | 2015-07-07 11:46:32 +0000 | |
---|---|---|
committer | 2015-07-07 16:33:14 +0000 | |
commit | 2eacd983bb5ff9a28b58a626bf956ed1b113c777 (patch) | |
tree | 84e112c448900d1336205e2392478589c9621ad6 /src/main/java/com/google/devtools/build/lib | |
parent | 130246293c7c36d6538c78e82b59cac343b37c48 (diff) |
Support (test) timeouts in Bazel.
Fixes #279.
--
MOS_MIGRATED_REVID=97661546
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java | 11 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java | 18 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java index ddea658f5f..a391a30869 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java @@ -39,6 +39,7 @@ import com.google.devtools.common.options.OptionsClassProvider; import java.io.Closeable; import java.io.IOException; +import java.util.HashMap; import java.util.Map; /** @@ -76,16 +77,24 @@ public class StandaloneTestStrategy extends TestStrategy { .getChild(getTmpDirName(action.getExecutionSettings().getExecutable().getExecPath())); Path workingDirectory = runfilesDir.getRelative(action.getRunfilesPrefix()); + TestRunnerAction.ResolvedPaths resolvedPaths = action.resolve(actionExecutionContext.getExecutor().getExecRoot()); Map<String, String> env = getEnv(action, runfilesDir, testTmpDir, resolvedPaths); + + Map<String, String> info = new HashMap<>(); + + // This key is only understood by StandaloneSpawnStrategy. + info.put("timeout", "" + getTimeout(action)); + info.putAll(action.getTestProperties().getExecutionInfo()); + Spawn spawn = new BaseSpawn( // Bazel lacks much of the tooling for coverage, so we don't attempt to pass a coverage // script here. getArgs(TEST_SETUP, "", action), env, - action.getTestProperties().getExecutionInfo(), + info, action, action .getTestProperties() diff --git a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java index 0b034b490e..92f7a3cad0 100644 --- a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneSpawnStrategy.java @@ -62,6 +62,16 @@ public class StandaloneSpawnStrategy implements SpawnActionContext { + "]", spawn.asShellCommand(executor.getExecRoot())); } + int timeout = -1; + String timeoutStr = spawn.getExecutionInfo().get("timeout"); + if (timeoutStr != null) { + try { + timeout = Integer.parseInt(timeoutStr); + } catch (NumberFormatException e) { + throw new UserExecException("could not parse timeout: " + e); + } + } + // We must wrap the subprocess with process-wrapper to kill the process tree. // All actions therefore depend on the process-wrapper file. Since it's embedded, // we don't bother with declaring it as an input. @@ -72,13 +82,13 @@ public class StandaloneSpawnStrategy implements SpawnActionContext { // Disable it for now to make the setup easier and to avoid further PATH hacks. // Ideally we should have a native implementation of process-wrapper for Windows. args.add(processWrapper.getPathString()); - args.add("-1"); /* timeout */ - args.add("0"); /* kill delay. */ + args.add("" + timeout); + args.add("5"); /* kill delay: give some time to print stacktraces and whatnot. */ // TODO(bazel-team): use process-wrapper redirection so we don't have to // pass test logs through the Java heap. - args.add("-"); /* stdout. */ - args.add("-"); /* stderr. */ + args.add("-"); /* stdout. */ + args.add("-"); /* stderr. */ } args.addAll(spawn.getArguments()); |