Skip to content

Commit

Permalink
Move materialization for failed actions tests out of uncategorized
Browse files Browse the repository at this point in the history
Summary: To reduce the number of tests in test_uncategorized

Reviewed By: iguridi

Differential Revision: D69629898

fbshipit-source-id: 906dede1bff056c1ef3dbf1fa1c154a3b73a9043
  • Loading branch information
Will-MingLun-Li authored and facebook-github-bot committed Feb 18, 2025
1 parent cbd628b commit ee5ccc2
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 96 deletions.
112 changes: 112 additions & 0 deletions tests/core/build/test_materialization_for_failed_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

# pyre-strict


from pathlib import Path

from buck2.tests.e2e_util.api.buck import Buck
from buck2.tests.e2e_util.asserts import expect_failure
from buck2.tests.e2e_util.buck_workspace import buck_test
from buck2.tests.e2e_util.helper.utils import json_get, random_string


@buck_test(data_dir="materialize_inputs_for_failed_actions")
async def test_materialize_inputs_for_failed_actions(buck: Buck) -> None:
await expect_failure(
buck.build(
"//:action_fail",
"--remote-only",
"--no-remote-cache",
"--materialize-failed-inputs",
"-c",
f"test.cache_buster={random_string()}",
),
)

log = (await buck.log("show")).stdout.strip().splitlines()

found_action_error = False
found_materialize_failed_inputs_span = False

for line in log:
# Look for MaterializeFailedInputs ReStage event
if "MaterializeFailedInputs" in line:
found_materialize_failed_inputs_span = True

# Inspect failed input
materialized_inputs_for_failed = json_get(
line,
"Event",
"data",
"Instant",
"data",
"ActionError",
"last_command",
"details",
"command_kind",
"command",
"RemoteCommand",
"materialized_inputs_for_failed",
)

if materialized_inputs_for_failed:
found_action_error = True
assert len(materialized_inputs_for_failed) == 1
input = materialized_inputs_for_failed[0]
with open(Path(buck.cwd / input), "r") as materialized_input_path:
contents = materialized_input_path.read()
assert contents == "yay!"

if not found_action_error:
raise AssertionError("Did not find relevant ActionError")
if not found_materialize_failed_inputs_span:
raise AssertionError("Did not find relevant MaterializeFailedInputs span")


@buck_test(data_dir="materialize_outputs_for_failed_actions")
async def test_materialize_outputs_for_failed_actions(buck: Buck) -> None:
await expect_failure(
buck.build(
"//:action_fail",
"--remote-only",
"--no-remote-cache",
"--unstable-materialize-failed-action-outputs=json",
"-c",
f"test.cache_buster={random_string()}",
),
)

log = (await buck.log("show")).stdout.strip().splitlines()

found_action_error = False

for line in log:
# Inspect failed output
materialized_outputs_for_failed = json_get(
line,
"Event",
"data",
"Instant",
"data",
"ActionError",
"last_command",
"details",
"command_kind",
"command",
"RemoteCommand",
"materialized_outputs_for_failed_actions",
)

if materialized_outputs_for_failed:
found_action_error = True
assert len(materialized_outputs_for_failed) == 1
materialized_outputs_for_failed[0].endswith("json")

if not found_action_error:
raise AssertionError("Did not find relevant ActionError")
96 changes: 0 additions & 96 deletions tests/core/build/test_uncategorized.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,102 +412,6 @@ async def test_tmpdir(buck: Buck) -> None:
await buck.build("root//:")


@buck_test(data_dir="materialize_inputs_for_failed_actions")
async def test_materialize_inputs_for_failed_actions(buck: Buck) -> None:
await expect_failure(
buck.build(
"//:action_fail",
"--remote-only",
"--no-remote-cache",
"--materialize-failed-inputs",
"-c",
f"test.cache_buster={random_string()}",
),
)

log = (await buck.log("show")).stdout.strip().splitlines()

found_action_error = False
found_materialize_failed_inputs_span = False

for line in log:
# Look for MaterializeFailedInputs ReStage event
if "MaterializeFailedInputs" in line:
found_materialize_failed_inputs_span = True

# Inspect failed input
materialized_inputs_for_failed = json_get(
line,
"Event",
"data",
"Instant",
"data",
"ActionError",
"last_command",
"details",
"command_kind",
"command",
"RemoteCommand",
"materialized_inputs_for_failed",
)

if materialized_inputs_for_failed:
found_action_error = True
assert len(materialized_inputs_for_failed) == 1
input = materialized_inputs_for_failed[0]
with open(Path(buck.cwd / input), "r") as materialized_input_path:
contents = materialized_input_path.read()
assert contents == "yay!"

if not found_action_error:
raise AssertionError("Did not find relevant ActionError")
if not found_materialize_failed_inputs_span:
raise AssertionError("Did not find relevant MaterializeFailedInputs span")


@buck_test(data_dir="materialize_outputs_for_failed_actions")
async def test_materialize_outputs_for_failed_actions(buck: Buck) -> None:
await expect_failure(
buck.build(
"//:action_fail",
"--remote-only",
"--no-remote-cache",
"--unstable-materialize-failed-action-outputs=json",
"-c",
f"test.cache_buster={random_string()}",
),
)

log = (await buck.log("show")).stdout.strip().splitlines()

found_action_error = False

for line in log:
# Inspect failed output
materialized_outputs_for_failed = json_get(
line,
"Event",
"data",
"Instant",
"data",
"ActionError",
"last_command",
"details",
"command_kind",
"command",
"RemoteCommand",
"materialized_outputs_for_failed_actions",
)

if materialized_outputs_for_failed:
found_action_error = True
assert len(materialized_outputs_for_failed) == 1
materialized_outputs_for_failed[0].endswith("json")

if not found_action_error:
raise AssertionError("Did not find relevant ActionError")


def random_string() -> str:
return "".join(random.choice(string.ascii_lowercase) for i in range(256))

Expand Down

0 comments on commit ee5ccc2

Please sign in to comment.