Skip to content

Commit 7d7f8ef

Browse files
committed
Add smoketest for bpt secrets and gracefully shutdown devboxes when test fails
1 parent d61d45b commit 7d7f8ef

2 files changed

Lines changed: 58 additions & 17 deletions

File tree

tests/smoketests/test_blueprints.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,58 @@ def test_create_blueprint_and_await_build(client: Runloop) -> None:
4545
@pytest.mark.timeout(30)
4646
def test_start_devbox_from_base_blueprint_by_id(client: Runloop) -> None:
4747
assert _blueprint_id
48-
devbox = client.devboxes.create_and_await_running(
48+
devbox = None
49+
try:
50+
devbox = client.devboxes.create_and_await_running(
4951
blueprint_id=_blueprint_id,
5052
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
5153
)
52-
assert devbox.blueprint_id == _blueprint_id
53-
assert devbox.status == "running"
54-
client.devboxes.shutdown(devbox.id)
54+
assert devbox.blueprint_id == _blueprint_id
55+
assert devbox.status == "running"
56+
finally:
57+
if devbox:
58+
client.devboxes.shutdown(devbox.id)
5559

5660

5761
@pytest.mark.timeout(30)
5862
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)
63+
devbox = None
64+
try:
65+
devbox = client.devboxes.create_and_await_running(
66+
blueprint_name=_blueprint_name,
67+
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
68+
)
69+
assert devbox.blueprint_id
70+
assert devbox.status == "running"
71+
finally:
72+
if devbox:
73+
client.devboxes.shutdown(devbox.id)
74+
75+
76+
@pytest.mark.timeout(60)
77+
def test_create_blueprint_with_secret_and_await_build(client: Runloop) -> None:
78+
bpt = None
79+
try:
80+
bpt = client.blueprints.create(
81+
name=unique_name("bp-secrets"),
82+
dockerfile=(
83+
"FROM runloop:runloop/starter-arm64\n"
84+
"ARG GITHUB_TOKEN\n"
85+
"RUN git config --global credential.helper '!f() { echo \"username=x-access-token\"; echo \"password=$GITHUB_TOKEN\"; }; f' "
86+
"&& git clone https://github.com/runloopai/runloop-fe.git /workspace/runloop-fe "
87+
"&& git config --global --unset credential.helper\n"
88+
"WORKDIR /workspace/runloop-fe"
89+
),
90+
secrets={"GITHUB_TOKEN": "GITHUB_TOKEN_FOR_SMOKETESTS"},
91+
)
92+
# Wait for build to complete
93+
completed = client.blueprints.await_build_complete(
94+
bpt.id,
95+
polling_config=PollingConfig(max_attempts=180, interval_seconds=5.0, timeout_seconds=30 * 60),
96+
)
97+
assert completed.status == "build_complete"
98+
assert completed.parameters.secrets is not None
99+
assert completed.parameters.secrets.get("GITHUB_TOKEN") == "GITHUB_TOKEN_FOR_SMOKETESTS"
100+
finally:
101+
if bpt:
102+
client.blueprints.delete(bpt.id)

tests/smoketests/test_snapshots.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ def test_snapshot_devbox(client: Runloop) -> None:
4848
@pytest.mark.timeout(30)
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)