mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Add timeout option to Cloudrun build (#1717)
* Add timeout option for build phase * Make the --timeout setting optional * Add test for --timeout setting Thanks, @wragge
This commit is contained in:
parent
d57c347f35
commit
3001e1e394
2 changed files with 30 additions and 13 deletions
|
|
@ -105,18 +105,19 @@ def test_publish_cloudrun(mock_call, mock_output, mock_which, tmp_path_factory):
|
|||
@mock.patch("datasette.publish.cloudrun.check_output")
|
||||
@mock.patch("datasette.publish.cloudrun.check_call")
|
||||
@pytest.mark.parametrize(
|
||||
"memory,cpu,expected_gcloud_args",
|
||||
"memory,cpu,timeout,expected_gcloud_args",
|
||||
[
|
||||
["1Gi", None, "--memory 1Gi"],
|
||||
["2G", None, "--memory 2G"],
|
||||
["256Mi", None, "--memory 256Mi"],
|
||||
["4", None, None],
|
||||
["GB", None, None],
|
||||
[None, 1, "--cpu 1"],
|
||||
[None, 2, "--cpu 2"],
|
||||
[None, 3, None],
|
||||
[None, 4, "--cpu 4"],
|
||||
["2G", 4, "--memory 2G --cpu 4"],
|
||||
["1Gi", None, None, "--memory 1Gi"],
|
||||
["2G", None, None, "--memory 2G"],
|
||||
["256Mi", None, None, "--memory 256Mi"],
|
||||
["4", None, None, None],
|
||||
["GB", None, None, None],
|
||||
[None, 1, None, "--cpu 1"],
|
||||
[None, 2, None, "--cpu 2"],
|
||||
[None, 3, None, None],
|
||||
[None, 4, None, "--cpu 4"],
|
||||
["2G", 4, None, "--memory 2G --cpu 4"],
|
||||
[None, None, 1800, "--timeout 1800"],
|
||||
],
|
||||
)
|
||||
def test_publish_cloudrun_memory_cpu(
|
||||
|
|
@ -125,6 +126,7 @@ def test_publish_cloudrun_memory_cpu(
|
|||
mock_which,
|
||||
memory,
|
||||
cpu,
|
||||
timeout,
|
||||
expected_gcloud_args,
|
||||
tmp_path_factory,
|
||||
):
|
||||
|
|
@ -139,6 +141,8 @@ def test_publish_cloudrun_memory_cpu(
|
|||
args.extend(["--memory", memory])
|
||||
if cpu:
|
||||
args.extend(["--cpu", str(cpu)])
|
||||
if timeout:
|
||||
args.extend(["--timeout", str(timeout)])
|
||||
result = runner.invoke(cli.cli, args)
|
||||
if expected_gcloud_args is None:
|
||||
assert 2 == result.exit_code
|
||||
|
|
@ -149,13 +153,16 @@ def test_publish_cloudrun_memory_cpu(
|
|||
"gcloud run deploy --allow-unauthenticated --platform=managed"
|
||||
" --image {} test".format(tag)
|
||||
)
|
||||
expected_build_call = f"gcloud builds submit --tag {tag}"
|
||||
if memory:
|
||||
expected_call += " --memory {}".format(memory)
|
||||
if cpu:
|
||||
expected_call += " --cpu {}".format(cpu)
|
||||
if timeout:
|
||||
expected_build_call += f" --timeout {timeout}"
|
||||
mock_call.assert_has_calls(
|
||||
[
|
||||
mock.call(f"gcloud builds submit --tag {tag}", shell=True),
|
||||
mock.call(expected_build_call, shell=True),
|
||||
mock.call(
|
||||
expected_call,
|
||||
shell=True,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue