-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_devboxes.py
More file actions
88 lines (65 loc) · 2.64 KB
/
test_devboxes.py
File metadata and controls
88 lines (65 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import annotations
from typing import Iterator
import pytest
from runloop_api_client import Runloop
from runloop_api_client.lib.polling import PollingConfig, PollingTimeout
from .utils import unique_name
pytestmark = [pytest.mark.smoketest]
@pytest.fixture(autouse=True, scope="module")
def _cleanup(client: Runloop) -> Iterator[None]: # pyright: ignore[reportUnusedFunction]
yield
global _devbox_id
if _devbox_id:
try:
client.devboxes.shutdown(_devbox_id)
except Exception:
pass
"""
Tests are run sequentially and can be dependent on each other.
This is to avoid overloading resources and save efficiency.
"""
_devbox_id = None
@pytest.mark.timeout(30)
def test_create_devbox(client: Runloop) -> None:
created = client.devboxes.create(name=unique_name("smoke-devbox"))
assert created.id
client.devboxes.shutdown(created.id)
@pytest.mark.timeout(30)
def test_await_running_create_and_await_running(client: Runloop) -> None:
global _devbox_id
created = client.devboxes.create_and_await_running(
name=unique_name("smoketest-devbox2"),
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
)
assert created.status == "running"
_devbox_id = created.id
def test_list_devboxes(client: Runloop) -> None:
page = client.devboxes.list(limit=10)
assert isinstance(page.devboxes, list)
assert len(page.devboxes) > 0
def test_retrieve_devbox(client: Runloop) -> None:
assert _devbox_id
view = client.devboxes.retrieve(_devbox_id)
assert view.id == _devbox_id
def test_shutdown_devbox(client: Runloop) -> None:
assert _devbox_id
view = client.devboxes.shutdown(_devbox_id)
assert view.id == _devbox_id
assert view.status == "shutdown"
@pytest.mark.timeout(90)
def test_create_and_await_running_long_set_up(client: Runloop) -> None:
created = client.devboxes.create_and_await_running(
name=unique_name("smoketest-devbox-await-running-long-set-up"),
launch_parameters={"launch_commands": ["sleep 70"]},
polling_config=PollingConfig(interval_seconds=5.0, timeout_seconds=80),
)
assert created.status == "running"
client.devboxes.shutdown(created.id)
@pytest.mark.timeout(30)
def test_create_and_await_running_timeout(client: Runloop) -> None:
with pytest.raises(PollingTimeout):
client.devboxes.create_and_await_running(
name=unique_name("smoketest-devbox-await-running-timeout"),
launch_parameters={"launch_commands": ["sleep 70"]},
polling_config=PollingConfig(max_attempts=1, interval_seconds=0.1),
)