Skip to content

Commit

Permalink
Propagate test envs to xml generation action
Browse files Browse the repository at this point in the history
Previously, we hardcode the envs of the xml generation action, which
caused problem for process-wrapper because it's dynamically linked to
some system library and the required PATH or LD_LIBRARY_PATH are not
set.

This change propagate the envs we set for the actual test action to the
xml file generation action to make sure the env vars are correctly set and
can also be controlled by --action_env and --test_env.

Fixes #4137
  • Loading branch information
meteorcloudy committed Dec 8, 2020
1 parent 52457b1 commit de33fde
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,26 +391,23 @@ private static BuildEventStreamProtos.TestResult.ExecutionInfo extractExecutionI
* A spawn to generate a test.xml file from the test log. This is only used if the test does not
* generate a test.xml file itself.
*/
private static Spawn createXmlGeneratingSpawn(TestRunnerAction action, SpawnResult result) {
private static Spawn createXmlGeneratingSpawn(TestRunnerAction action, ImmutableMap<String, String> testEnv, SpawnResult result) {
ImmutableList<String> args =
ImmutableList.of(
action.getTestXmlGeneratorScript().getExecPath().getCallablePathString(),
action.getTestLog().getExecPathString(),
action.getXmlOutputPath().getPathString(),
Long.toString(result.getWallTime().orElse(Duration.ZERO).getSeconds()),
Integer.toString(result.exitCode()));

String testBinaryName =
action.getExecutionSettings().getExecutable().getRootRelativePath().getCallablePathString();
ImmutableMap.Builder<String, String> envBuilder = ImmutableMap.builder();
envBuilder.putAll(testEnv)
.put("TEST_SHARD_INDEX", Integer.toString(action.getShardNum()))
.put("TEST_TOTAL_SHARDS", Integer.toString(action.getExecutionSettings().getTotalShards()))
.put("TEST_NAME", action.getTestName());
return new SimpleSpawn(
action,
args,
ImmutableMap.of(
"PATH", "/usr/bin:/bin",
"TEST_SHARD_INDEX", Integer.toString(action.getShardNum()),
"TEST_TOTAL_SHARDS", Integer.toString(action.getExecutionSettings().getTotalShards()),
"TEST_NAME", action.getTestName(),
"TEST_BINARY", testBinaryName),
envBuilder.build(),
// Pass the execution info of the action which is identical to the supported tags set on the
// test target. In particular, this does not set the test timeout on the spawn.
ImmutableMap.copyOf(action.getExecutionInfo()),
Expand Down Expand Up @@ -766,7 +763,8 @@ public TestAttemptContinuation execute()
if (executionOptions.splitXmlGeneration
&& fileOutErr.getOutputPath().exists()
&& !xmlOutputPath.exists()) {
Spawn xmlGeneratingSpawn = createXmlGeneratingSpawn(testAction, spawnResults.get(0));

Spawn xmlGeneratingSpawn = createXmlGeneratingSpawn(testAction, spawn.getEnvironment(), spawnResults.get(0));
SpawnStrategyResolver spawnStrategyResolver =
actionExecutionContext.getContext(SpawnStrategyResolver.class);
// We treat all failures to generate the test.xml here as catastrophic, and won't rerun
Expand Down

0 comments on commit de33fde

Please sign in to comment.