Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test for function build cancelation #383

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/383.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add test checking function cancelation when linked compute plans are all canceled.
39 changes: 39 additions & 0 deletions tests/test_docker_image_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,42 @@ def test_function_build_order(factory, cfg, client, worker):
function_3 = function_getter("function", function_3["key"])
assert function_2["status"] == "FUNCTION_STATUS_BUILDING"
assert function_3["status"] == "FUNCTION_STATUS_WAITING"


@pytest.mark.remote_only
def test_function_cancelled_cp(factory, cfg, client, worker, default_dataset):
"""
Test that if you cancelled a CP and a function is linked to tasks that are oinly in CP canceled or faiuled,
the function will be canceled
"""
docker_image = cfg.base_docker_image
function_category = FunctionCategory.simple

# We create 2 functions, so when the second one should start building, the CP is already been canceled
dockerfile_wait = get_dockerfile(
docker_image, function_category, extra_instructions="ENV test=test_function_cancelled_cp_wait\nRUN sleep 5"
)
dockerfile_test = get_dockerfile(
docker_image, function_category, extra_instructions="ENV test=test_function_cancelled_cp_test"
)

function_wait_spec = factory.create_function(function_category, dockerfile=dockerfile_wait)
function_test_spec = factory.create_function(function_category, dockerfile=dockerfile_test)

inputs = default_dataset.opener_input + default_dataset.train_data_sample_inputs
cp = factory.create_compute_plan()
function_wait = client.add_function(function_wait_spec)
cp.create_traintask(function=function_wait, worker=worker, inputs=inputs)
function_test = client.add_function(function_test_spec)
cp.create_traintask(function=function_test, worker=worker, inputs=inputs)
client.add_compute_plan(cp)

client.cancel_compute_plan(cp.key)
cp = client.wait_compute_plan(cp.key, raise_on_failure=False, timeout=cfg.options.future_timeout)
assert cp.status == "PLAN_STATUS_CANCELED"

# Check that `function_wait` (built first) reaches status DONE or CANCELED
function_wait = client.wait_function(function_wait.key, raise_on_failure=False, timeout=cfg.options.future_timeout)
assert function_wait.status != "FUNCTION_STATUS_FAILED"
function_test = client.wait_function(function_test.key, raise_on_failure=False, timeout=cfg.options.future_timeout)
assert function_test.status == "FUNCTION_STATUS_CANCELED"