pytest-neon 2.1.0__py3-none-any.whl → 2.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_neon/__init__.py +1 -1
- pytest_neon/plugin.py +88 -3
- {pytest_neon-2.1.0.dist-info → pytest_neon-2.1.2.dist-info}/METADATA +1 -1
- pytest_neon-2.1.2.dist-info/RECORD +8 -0
- pytest_neon-2.1.0.dist-info/RECORD +0 -8
- {pytest_neon-2.1.0.dist-info → pytest_neon-2.1.2.dist-info}/WHEEL +0 -0
- {pytest_neon-2.1.0.dist-info → pytest_neon-2.1.2.dist-info}/entry_points.txt +0 -0
- {pytest_neon-2.1.0.dist-info → pytest_neon-2.1.2.dist-info}/licenses/LICENSE +0 -0
pytest_neon/__init__.py
CHANGED
pytest_neon/plugin.py
CHANGED
|
@@ -396,7 +396,8 @@ def _reset_branch_to_parent(
|
|
|
396
396
|
"""Reset a branch to its parent's state using the Neon API.
|
|
397
397
|
|
|
398
398
|
Uses exponential backoff retry logic to handle transient API errors
|
|
399
|
-
that can occur during parallel test execution.
|
|
399
|
+
that can occur during parallel test execution. After initiating the
|
|
400
|
+
restore, polls the operation status until it completes.
|
|
400
401
|
|
|
401
402
|
Args:
|
|
402
403
|
branch: The branch to reset
|
|
@@ -406,7 +407,10 @@ def _reset_branch_to_parent(
|
|
|
406
407
|
if not branch.parent_id:
|
|
407
408
|
raise RuntimeError(f"Branch {branch.branch_id} has no parent - cannot reset")
|
|
408
409
|
|
|
409
|
-
|
|
410
|
+
base_url = "https://console.neon.tech/api/v2"
|
|
411
|
+
project_id = branch.project_id
|
|
412
|
+
branch_id = branch.branch_id
|
|
413
|
+
restore_url = f"{base_url}/projects/{project_id}/branches/{branch_id}/restore"
|
|
410
414
|
headers = {
|
|
411
415
|
"Authorization": f"Bearer {api_key}",
|
|
412
416
|
"Content-Type": "application/json",
|
|
@@ -416,12 +420,27 @@ def _reset_branch_to_parent(
|
|
|
416
420
|
for attempt in range(max_retries + 1):
|
|
417
421
|
try:
|
|
418
422
|
response = requests.post(
|
|
419
|
-
|
|
423
|
+
restore_url,
|
|
420
424
|
headers=headers,
|
|
421
425
|
json={"source_branch_id": branch.parent_id},
|
|
422
426
|
timeout=30,
|
|
423
427
|
)
|
|
424
428
|
response.raise_for_status()
|
|
429
|
+
|
|
430
|
+
# The restore API returns operations that run asynchronously.
|
|
431
|
+
# We must wait for operations to complete before the next test
|
|
432
|
+
# starts, otherwise connections may fail during the restore.
|
|
433
|
+
data = response.json()
|
|
434
|
+
operations = data.get("operations", [])
|
|
435
|
+
|
|
436
|
+
if operations:
|
|
437
|
+
_wait_for_operations(
|
|
438
|
+
project_id=branch.project_id,
|
|
439
|
+
operations=operations,
|
|
440
|
+
headers=headers,
|
|
441
|
+
base_url=base_url,
|
|
442
|
+
)
|
|
443
|
+
|
|
425
444
|
return # Success
|
|
426
445
|
except requests.RequestException as e:
|
|
427
446
|
last_error = e
|
|
@@ -434,6 +453,72 @@ def _reset_branch_to_parent(
|
|
|
434
453
|
raise last_error # type: ignore[misc]
|
|
435
454
|
|
|
436
455
|
|
|
456
|
+
def _wait_for_operations(
|
|
457
|
+
project_id: str,
|
|
458
|
+
operations: list[dict[str, Any]],
|
|
459
|
+
headers: dict[str, str],
|
|
460
|
+
base_url: str,
|
|
461
|
+
max_wait_seconds: float = 60,
|
|
462
|
+
poll_interval: float = 0.5,
|
|
463
|
+
) -> None:
|
|
464
|
+
"""Wait for Neon operations to complete.
|
|
465
|
+
|
|
466
|
+
Args:
|
|
467
|
+
project_id: The Neon project ID
|
|
468
|
+
operations: List of operation dicts from the API response
|
|
469
|
+
headers: HTTP headers including auth
|
|
470
|
+
base_url: Base URL for Neon API
|
|
471
|
+
max_wait_seconds: Maximum time to wait (default: 60s)
|
|
472
|
+
poll_interval: Time between polls (default: 0.5s)
|
|
473
|
+
"""
|
|
474
|
+
# Get operation IDs that aren't already finished
|
|
475
|
+
pending_op_ids = [
|
|
476
|
+
op["id"] for op in operations if op.get("status") not in ("finished", "skipped")
|
|
477
|
+
]
|
|
478
|
+
|
|
479
|
+
if not pending_op_ids:
|
|
480
|
+
return # All operations already complete
|
|
481
|
+
|
|
482
|
+
waited = 0.0
|
|
483
|
+
first_poll = True
|
|
484
|
+
while pending_op_ids and waited < max_wait_seconds:
|
|
485
|
+
# Poll immediately first time (operation usually completes instantly),
|
|
486
|
+
# then wait between subsequent polls
|
|
487
|
+
if first_poll:
|
|
488
|
+
time.sleep(0.1) # Tiny delay to let operation start
|
|
489
|
+
waited += 0.1
|
|
490
|
+
first_poll = False
|
|
491
|
+
else:
|
|
492
|
+
time.sleep(poll_interval)
|
|
493
|
+
waited += poll_interval
|
|
494
|
+
|
|
495
|
+
# Check status of each pending operation
|
|
496
|
+
still_pending = []
|
|
497
|
+
for op_id in pending_op_ids:
|
|
498
|
+
op_url = f"{base_url}/projects/{project_id}/operations/{op_id}"
|
|
499
|
+
try:
|
|
500
|
+
response = requests.get(op_url, headers=headers, timeout=10)
|
|
501
|
+
response.raise_for_status()
|
|
502
|
+
op_data = response.json().get("operation", {})
|
|
503
|
+
status = op_data.get("status")
|
|
504
|
+
|
|
505
|
+
if status == "error":
|
|
506
|
+
err = op_data.get("error", "unknown error")
|
|
507
|
+
raise RuntimeError(f"Operation {op_id} failed: {err}")
|
|
508
|
+
if status not in ("finished", "skipped"):
|
|
509
|
+
still_pending.append(op_id)
|
|
510
|
+
except requests.RequestException:
|
|
511
|
+
# On network error, assume still pending and retry
|
|
512
|
+
still_pending.append(op_id)
|
|
513
|
+
|
|
514
|
+
pending_op_ids = still_pending
|
|
515
|
+
|
|
516
|
+
if pending_op_ids:
|
|
517
|
+
raise RuntimeError(
|
|
518
|
+
f"Timeout waiting for operations to complete: {pending_op_ids}"
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
|
|
437
522
|
@pytest.fixture(scope="session")
|
|
438
523
|
def _neon_migration_branch(
|
|
439
524
|
request: pytest.FixtureRequest,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytest-neon
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: Pytest plugin for Neon database branch isolation in tests
|
|
5
5
|
Project-URL: Homepage, https://github.com/ZainRizvi/pytest-neon
|
|
6
6
|
Project-URL: Repository, https://github.com/ZainRizvi/pytest-neon
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pytest_neon/__init__.py,sha256=EKni9NpcUiIPy8J8vj-s6oKH6S98JlNs5JYuF151cMA,398
|
|
2
|
+
pytest_neon/plugin.py,sha256=r30wz96rQZerAiAF8wAVmWPksF6lM2dsJyUNj2X9rWo,38038
|
|
3
|
+
pytest_neon/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
pytest_neon-2.1.2.dist-info/METADATA,sha256=QA7xaOCbi_wD8LTwb8gWQpZe8rG8BWcMrETS78HUOks,18734
|
|
5
|
+
pytest_neon-2.1.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
+
pytest_neon-2.1.2.dist-info/entry_points.txt,sha256=5U88Idj_G8-PSDb9VF3OwYFbGLHnGOo_GxgYvi0dtXw,37
|
|
7
|
+
pytest_neon-2.1.2.dist-info/licenses/LICENSE,sha256=aKKp_Ex4WBHTByY4BhXJ181dzB_qYhi2pCUmZ7Spn_0,1067
|
|
8
|
+
pytest_neon-2.1.2.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
pytest_neon/__init__.py,sha256=69SoGL2ciE38uvrXpEQPXiBFDkbWct7hl_k9MmswcSU,398
|
|
2
|
-
pytest_neon/plugin.py,sha256=rb9CgOqle-sQHHoyFO5xDZ5wzrHx_4BLygiVywEYGbM,34949
|
|
3
|
-
pytest_neon/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
pytest_neon-2.1.0.dist-info/METADATA,sha256=ebdenaxT8v4GQeepZCglp04mb92iwJxp1PMnnS-9Nqs,18734
|
|
5
|
-
pytest_neon-2.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
-
pytest_neon-2.1.0.dist-info/entry_points.txt,sha256=5U88Idj_G8-PSDb9VF3OwYFbGLHnGOo_GxgYvi0dtXw,37
|
|
7
|
-
pytest_neon-2.1.0.dist-info/licenses/LICENSE,sha256=aKKp_Ex4WBHTByY4BhXJ181dzB_qYhi2pCUmZ7Spn_0,1067
|
|
8
|
-
pytest_neon-2.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|