-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_snapshots.py
More file actions
60 lines (46 loc) · 1.64 KB
/
Copy pathtest_snapshots.py
File metadata and controls
60 lines (46 loc) · 1.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
from __future__ import annotations
from typing import Iterator
import pytest
from runloop_api_client import Runloop
from runloop_api_client.lib.polling import PollingConfig
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
_snapshot_id = None
@pytest.mark.timeout(30)
def test_snapshot_devbox(client: Runloop) -> None:
global _devbox_id, _snapshot_id
created = client.devboxes.create_and_await_running(
name=unique_name("snap-devbox"),
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
)
_devbox_id = created.id
snap = client.devboxes.snapshot_disk(_devbox_id, name=unique_name("snap"))
assert snap.id
_snapshot_id = snap.id
@pytest.mark.timeout(120)
def test_launch_devbox_from_snapshot(client: Runloop) -> None:
assert _snapshot_id
launched = None
try:
launched = client.devboxes.create_and_await_running(
snapshot_id=_snapshot_id,
polling_config=PollingConfig(max_attempts=120, interval_seconds=5.0, timeout_seconds=20 * 60),
)
assert launched.snapshot_id == _snapshot_id
finally:
if launched:
client.devboxes.shutdown(launched.id)