Skip to content

Commit 12ad10d

Browse files
authored
Add smoketest for bpt secrets and gracefully shutdown devboxes (#656)
* Add smoketest for bpt secrets and gracefully shutdown devboxes when test fails * format * Disable secrets test if local dev * fix tests * extend test timeouts
1 parent 021842c commit 12ad10d

File tree

3 files changed

+72
-26
lines changed

3 files changed

+72
-26
lines changed

tests/smoketests/test_blueprints.py

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
from typing import Iterator
45

56
import pytest
@@ -31,7 +32,7 @@ def _cleanup(client: Runloop) -> Iterator[None]: # pyright: ignore[reportUnused
3132
_blueprint_name = unique_name("bp")
3233

3334

34-
@pytest.mark.timeout(30)
35+
@pytest.mark.timeout(120) # 2 minutes
3536
def test_create_blueprint_and_await_build(client: Runloop) -> None:
3637
global _blueprint_id
3738
created = client.blueprints.create_and_await_build_complete(
@@ -42,24 +43,65 @@ def test_create_blueprint_and_await_build(client: Runloop) -> None:
4243
_blueprint_id = created.id
4344

4445

45-
@pytest.mark.timeout(30)
46+
@pytest.mark.timeout(120)
4647
def test_start_devbox_from_base_blueprint_by_id(client: Runloop) -> None:
4748
assert _blueprint_id
48-
devbox = client.devboxes.create_and_await_running(
49-
blueprint_id=_blueprint_id,
50-
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
51-
)
52-
assert devbox.blueprint_id == _blueprint_id
53-
assert devbox.status == "running"
54-
client.devboxes.shutdown(devbox.id)
49+
devbox = None
50+
try:
51+
devbox = client.devboxes.create_and_await_running(
52+
blueprint_id=_blueprint_id,
53+
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
54+
)
55+
assert devbox.blueprint_id == _blueprint_id
56+
assert devbox.status == "running"
57+
finally:
58+
if devbox:
59+
client.devboxes.shutdown(devbox.id)
5560

5661

57-
@pytest.mark.timeout(30)
62+
@pytest.mark.timeout(120)
5863
def test_start_devbox_from_base_blueprint_by_name(client: Runloop) -> None:
59-
devbox = client.devboxes.create_and_await_running(
60-
blueprint_name=_blueprint_name,
61-
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
62-
)
63-
assert devbox.blueprint_id
64-
assert devbox.status == "running"
65-
client.devboxes.shutdown(devbox.id)
64+
devbox = None
65+
try:
66+
devbox = client.devboxes.create_and_await_running(
67+
blueprint_name=_blueprint_name,
68+
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
69+
)
70+
assert devbox.blueprint_id
71+
assert devbox.status == "running"
72+
finally:
73+
if devbox:
74+
client.devboxes.shutdown(devbox.id)
75+
76+
77+
@pytest.mark.timeout(120)
78+
@pytest.mark.skipif(
79+
os.getenv("RUN_SMOKETESTS") != "1",
80+
reason="Skip blueprint secrets test in local testing (requires RUN_SMOKETESTS=1)",
81+
)
82+
def test_create_blueprint_with_secret_and_await_build(client: Runloop) -> None:
83+
bpt = None
84+
try:
85+
bpt = client.blueprints.create(
86+
name=unique_name("bp-secrets"),
87+
dockerfile=(
88+
"FROM runloop:runloop/starter-arm64\n"
89+
"ARG GITHUB_TOKEN\n"
90+
'RUN git config --global credential.helper \'!f() { echo "username=x-access-token"; echo "password=$GITHUB_TOKEN"; }; f\' '
91+
"&& git clone https://github.com/runloopai/runloop-fe.git /workspace/runloop-fe "
92+
"&& git config --global --unset credential.helper\n"
93+
"WORKDIR /workspace/runloop-fe"
94+
),
95+
secrets={"GITHUB_TOKEN": "GITHUB_TOKEN_FOR_SMOKETESTS"},
96+
)
97+
98+
completed = client.blueprints.await_build_complete(
99+
bpt.id,
100+
polling_config=PollingConfig(max_attempts=180, interval_seconds=5.0, timeout_seconds=30 * 60),
101+
)
102+
assert completed.status == "build_complete"
103+
assert completed.parameters.secrets is not None
104+
assert completed.parameters.secrets.get("GITHUB_TOKEN") == "GITHUB_TOKEN_FOR_SMOKETESTS"
105+
finally:
106+
if bpt:
107+
client.blueprints.delete(bpt.id)

tests/smoketests/test_devboxes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_create_devbox(client: Runloop) -> None:
3737
client.devboxes.shutdown(created.id)
3838

3939

40-
@pytest.mark.timeout(30)
40+
@pytest.mark.timeout(120)
4141
def test_await_running_create_and_await_running(client: Runloop) -> None:
4242
global _devbox_id
4343
created = client.devboxes.create_and_await_running(
@@ -67,7 +67,7 @@ def test_shutdown_devbox(client: Runloop) -> None:
6767
assert view.status == "shutdown"
6868

6969

70-
@pytest.mark.timeout(90)
70+
@pytest.mark.timeout(120)
7171
def test_create_and_await_running_long_set_up(client: Runloop) -> None:
7272
created = client.devboxes.create_and_await_running(
7373
name=unique_name("smoketest-devbox-await-running-long-set-up"),

tests/smoketests/test_snapshots.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ def test_snapshot_devbox(client: Runloop) -> None:
4545
_snapshot_id = snap.id
4646

4747

48-
@pytest.mark.timeout(30)
48+
@pytest.mark.timeout(120)
4949
def test_launch_devbox_from_snapshot(client: Runloop) -> None:
5050
assert _snapshot_id
51-
launched = client.devboxes.create_and_await_running(
52-
snapshot_id=_snapshot_id,
53-
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
54-
)
55-
assert launched.snapshot_id == _snapshot_id
56-
client.devboxes.shutdown(launched.id)
51+
launched = None
52+
try:
53+
launched = client.devboxes.create_and_await_running(
54+
snapshot_id=_snapshot_id,
55+
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
56+
)
57+
assert launched.snapshot_id == _snapshot_id
58+
finally:
59+
if launched:
60+
client.devboxes.shutdown(launched.id)

0 commit comments

Comments
 (0)