Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebarrau committed Oct 12, 2023
1 parent 351be6c commit 2a846c7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,22 @@ public static Platform getPlatformProto(
return null;
}

Map<String, String> properties;
Map<String, String> properties = new HashMap<>();
if (!spawn.getCombinedExecProperties().isEmpty()) {
// Apply default exec properties if the execution platform does not already set
// exec_properties
if (spawn.getExecutionPlatform() == null
|| spawn.getExecutionPlatform().execProperties().isEmpty()) {
properties = new HashMap<>();
properties.putAll(defaultExecProperties);
properties.putAll(spawn.getCombinedExecProperties());
} else {
properties = spawn.getCombinedExecProperties();
}
} else if (spawn.getExecutionPlatform() != null) {
properties = new HashMap<>();
Platform.Builder platformBuilder = Platform.newBuilder();

String remoteExecutionProperties = spawn.getExecutionPlatform().remoteExecutionProperties();
if (!remoteExecutionProperties.isEmpty()) {
Platform.Builder platformBuilder = Platform.newBuilder();
// Try and get the platform info from the execution properties.
try {
TextFormat.getParser()
Expand All @@ -117,10 +115,12 @@ public static Platform getPlatformProto(
for (Property property : platformBuilder.getPropertiesList()) {
properties.put(property.getName(), property.getValue());
}
} else {
} else if (!spawn.getExecutionPlatform().execProperties().isEmpty()) {
properties.putAll(spawn.getExecutionPlatform().execProperties());
}
} else {
}

if (properties.isEmpty()) {
properties = defaultExecProperties;
}

Expand Down
91 changes: 76 additions & 15 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1336,19 +1336,11 @@ EOF
[[ ! -f bazel-bin/test.runfiles/MANIFEST ]] || fail "expected output manifest to exist"
}

# FIXME remove this comment
#
# - I run this test with: bazel test //src/test/shell/bazel/remote:remote_execution_test --test_filter=test_platform_default_properties_invalidation
# - I do not understand how to set the platform yet
function test_platform_default_properties_invalidation() {
# Test that when changing values of --remote_default_platform_properties all actions are
# invalidated.
# invalidated if no platform is used.
mkdir -p test
cat > test/BUILD << 'EOF'
platform(
name = "platform_without_any_exec_properties",
)
genrule(
name = "test",
srcs = [],
Expand All @@ -1358,26 +1350,22 @@ genrule(
EOF

bazel build \
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=1234" \
//test:test >& $TEST_log || fail "Failed to build //test:test"

expect_log "2 processes: 1 internal, 1 remote"

bazel build \
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=88888" \
//test:test >& $TEST_log || fail "Failed to build //test:test"

# Changing --remote_default_platform_properties value should invalidate SkyFrames in-memory
# caching and make it re-run the action.
expect_log "2 processes: 1 internal, 1 remote"
# FIXME the above assert fails

bazel build \
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=88888" \
//test:test >& $TEST_log || fail "Failed to build //test:test"
Expand All @@ -1389,7 +1377,6 @@ EOF
bazel shutdown

bazel build \
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=88888" \
//test:test >& $TEST_log || fail "Failed to build //test:test"
Expand All @@ -1399,7 +1386,6 @@ EOF
expect_log "1 process: 1 internal"

bazel build\
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=88888" \
--remote_default_platform_properties='properties:{name:"build" value:"1234"}' \
Expand All @@ -1411,6 +1397,81 @@ EOF
expect_log "Setting both --remote_default_platform_properties and --remote_default_exec_properties is not allowed"
}

function test_platform_default_properties_invalidation_with_platform_exec_properties() {
# Test that when changing values of --remote_default_platform_properties all actions are
# invalidated.
mkdir -p test
cat > test/BUILD << 'EOF'
platform(
name = "platform_without_any_exec_properties",
exec_properties = {
"foo": "bar",
},
)
genrule(
name = "test",
srcs = [],
outs = ["output.txt"],
cmd = "echo \"foo\" > \"$@\""
)
EOF

bazel build \
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=1234" \
//test:test >& $TEST_log || fail "Failed to build //test:test"

expect_log "2 processes: 1 internal, 1 remote"

bazel build \
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=88888" \
//test:test >& $TEST_log || fail "Failed to build //test:test"

# Changing --remote_default_platform_properties value does not invalidate SkyFrames
# given its is super-seeded by the platform exec_properties.
expect_log "1 process: 1 internal."
}

function test_platform_default_properties_invalidation_with_platform_remote_execution_properties() {
# Test that when changing values of --remote_default_platform_properties all actions are
# invalidated.
mkdir -p test
cat > test/BUILD << 'EOF'
platform(
name = "platform_without_any_exec_properties",
remote_execution_properties = """properties: {name: "foo" value: "baz"}""",
)
genrule(
name = "test",
srcs = [],
outs = ["output.txt"],
cmd = "echo \"foo\" > \"$@\""
)
EOF

bazel build \
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=1234" \
//test:test >& $TEST_log || fail "Failed to build //test:test"

expect_log "2 processes: 1 internal, 1 remote"

bazel build \
--extra_execution_platforms=//test:platform_without_any_exec_properties \
--remote_executor=grpc://localhost:${worker_port} \
--remote_default_exec_properties="build=88888" \
//test:test >& $TEST_log || fail "Failed to build //test:test"

# Changing --remote_default_platform_properties value does not invalidate SkyFrames
# given its is super-seeded by the platform remote_execution_properties.
expect_log "2 processes: 1 remote cache hit, 1 internal"
}

function test_combined_disk_remote_exec_with_flag_combinations() {
rm -f ${TEST_TMPDIR}/test_expected
Expand Down

0 comments on commit 2a846c7

Please sign in to comment.