-
Notifications
You must be signed in to change notification settings - Fork 6
fix: fail fast on signer HTTP 483 insufficient balance #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eliteprox
wants to merge
3
commits into
livepeer:main
Choose a base branch
from
eliteprox:fix/insufficient-balance-483
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """HTTP 483 (insufficient balance) must fail fast — no orch fallback.""" | ||
| from __future__ import annotations | ||
|
|
||
| from io import BytesIO | ||
| from unittest.mock import MagicMock, patch | ||
| from urllib.error import HTTPError | ||
|
|
||
| import pytest | ||
|
|
||
| from livepeer_gateway.byoc import _create_byoc_payment | ||
| from livepeer_gateway.errors import InsufficientBalance, NoOrchestratorAvailableError | ||
| from livepeer_gateway.lv2v import StartJobRequest, start_lv2v | ||
| from livepeer_gateway.orchestrator import request_json | ||
|
|
||
|
|
||
| def test_request_json_maps_483_to_insufficient_balance() -> None: | ||
| body = b'{"error":"Starter allowance exhausted"}' | ||
| err = HTTPError( | ||
| "https://signer.example/generate-live-payment", | ||
| 483, | ||
| "Insufficient Balance", | ||
| hdrs=None, # type: ignore[arg-type] | ||
| fp=BytesIO(body), | ||
| ) | ||
| with patch("livepeer_gateway.orchestrator.urlopen", side_effect=err): | ||
| with pytest.raises(InsufficientBalance, match="Starter allowance exhausted"): | ||
| request_json( | ||
| "https://signer.example/generate-live-payment", | ||
| payload={}, | ||
| ) | ||
|
|
||
|
|
||
| def test_create_byoc_payment_preserves_483_as_insufficient_balance() -> None: | ||
| info = MagicMock() | ||
| info.HasField.return_value = True | ||
| info.ticket_params.face_value = b"\x01" | ||
| info.SerializeToString.return_value = b"orchestrator-info" | ||
| err = HTTPError( | ||
| "https://signer.example/generate-live-payment", | ||
| 483, | ||
| "Insufficient Balance", | ||
| hdrs=None, # type: ignore[arg-type] | ||
| fp=BytesIO(b"Starter allowance exhausted"), | ||
| ) | ||
|
|
||
| with ( | ||
| patch("livepeer_gateway.orch_info.get_orch_info", return_value=info), | ||
| patch("livepeer_gateway.byoc.urlopen", side_effect=err), | ||
| ): | ||
| with pytest.raises(InsufficientBalance, match="Starter allowance exhausted"): | ||
| _create_byoc_payment( | ||
| orch_origin="https://orch.example:8936", | ||
| capability="noop", | ||
| livepeer_hdr="header", | ||
| signer_url="https://signer.example", | ||
| ) | ||
|
|
||
|
|
||
| def test_start_lv2v_fails_fast_on_483_without_orch_fallback() -> None: | ||
| info_a = MagicMock() | ||
| info_a.transcoder = "https://orch-a.example:8935" | ||
| info_b = MagicMock() | ||
| info_b.transcoder = "https://orch-b.example:8935" | ||
|
|
||
| cursor = MagicMock() | ||
| cursor.next.side_effect = [ | ||
| ("https://orch-a.example:8935", info_a), | ||
| ("https://orch-b.example:8935", info_b), | ||
| NoOrchestratorAvailableError("exhausted", rejections=[]), | ||
| ] | ||
|
|
||
| payment_session = MagicMock() | ||
| payment_session.get_payment.side_effect = InsufficientBalance( | ||
| "Signer returned HTTP 483 (insufficient balance) " | ||
| "(url=https://signer.example/generate-live-payment); " | ||
| "body='Starter allowance exhausted'" | ||
| ) | ||
|
|
||
| with ( | ||
| patch("livepeer_gateway.lv2v.orchestrator_selector", return_value=cursor), | ||
| patch("livepeer_gateway.lv2v.PaymentSession", return_value=payment_session), | ||
| patch("livepeer_gateway.lv2v.build_capabilities"), | ||
| ): | ||
| with pytest.raises(InsufficientBalance, match="Starter allowance exhausted"): | ||
| start_lv2v( | ||
| None, | ||
| StartJobRequest(model_id="noop"), | ||
| signer_url="https://signer.example", | ||
| discovery_url="https://discovery.example/raw", | ||
| ) | ||
|
|
||
| assert cursor.next.call_count == 1 | ||
| assert payment_session.get_payment.call_count == 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.