-
Notifications
You must be signed in to change notification settings - Fork 58
LCORE-741: Proper quota limiters configuration #679
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
Merged
tisnik
merged 4 commits into
lightspeed-core:main
from
tisnik:lcore-741-quota-limiters-configuration
Oct 16, 2025
Merged
Changes from 2 commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """Unit tests for QuotaHandlersConfiguration model.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from models.config import QuotaHandlersConfiguration, QuotaSchedulerConfiguration | ||
|
|
||
|
|
||
| def test_quota_handlers_configuration() -> None: | ||
| """Test the quota handlers configuration.""" | ||
| cfg = QuotaHandlersConfiguration( | ||
| sqlite=None, | ||
| postgres=None, | ||
| limiters=[], | ||
| scheduler=QuotaSchedulerConfiguration(period=10), | ||
| enable_token_history=False, | ||
| ) | ||
| assert cfg is not None | ||
| assert cfg.sqlite is None | ||
| assert cfg.postgres is None | ||
| assert cfg.limiters == [] | ||
| assert cfg.scheduler is not None | ||
| assert not cfg.enable_token_history | ||
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,60 @@ | ||
| """Unit tests for QuotaLimiterConfig model.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from models.config import QuotaLimiterConfiguration | ||
|
|
||
|
|
||
| def test_quota_limiter_configuration() -> None: | ||
| """Test the default configuration.""" | ||
| cfg = QuotaLimiterConfiguration( | ||
| type="cluster_limiter", | ||
| name="cluster_monthly_limits", | ||
| initial_quota=0, | ||
| quota_increase=10, | ||
| period="3 seconds", | ||
| ) | ||
| assert cfg is not None | ||
| assert cfg.type == "cluster_limiter" | ||
| assert cfg.name == "cluster_monthly_limits" | ||
| assert cfg.initial_quota == 0 | ||
| assert cfg.quota_increase == 10 | ||
| assert cfg.period == "3 seconds" | ||
|
|
||
|
|
||
| def test_quota_limiter_configuration_improper_value_1() -> None: | ||
| """Test the default configuration.""" | ||
| with pytest.raises(ValueError, match="Input should be greater than or equal to 0"): | ||
| _ = QuotaLimiterConfiguration( | ||
| type="cluster_limiter", | ||
| name="cluster_monthly_limits", | ||
| initial_quota=-1, | ||
| quota_increase=10, | ||
| period="3 seconds", | ||
| ) | ||
|
|
||
|
|
||
| def test_quota_limiter_configuration_improper_value_2() -> None: | ||
| """Test the default configuration.""" | ||
| with pytest.raises(ValueError, match="Input should be greater than or equal to 0"): | ||
| _ = QuotaLimiterConfiguration( | ||
| type="cluster_limiter", | ||
| name="cluster_monthly_limits", | ||
| initial_quota=1, | ||
| quota_increase=-10, | ||
| period="3 seconds", | ||
| ) | ||
|
|
||
|
|
||
| def test_quota_limiter_configuration_improper_value_3() -> None: | ||
| """Test the default configuration.""" | ||
| with pytest.raises( | ||
| ValueError, match="Input should be 'user_limiter' or 'cluster_limiter'" | ||
| ): | ||
| _ = QuotaLimiterConfiguration( | ||
| type="unknown_limiter", | ||
| name="cluster_monthly_limits", | ||
| initial_quota=1, | ||
| quota_increase=10, | ||
| period="3 seconds", | ||
| ) |
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,20 @@ | ||
| """Unit tests for QuotaSchedulerConfig model.""" | ||
|
|
||
| import pytest | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| from models.config import QuotaSchedulerConfiguration | ||
|
|
||
|
|
||
| def test_quota_scheduler_default_configuration() -> None: | ||
| """Test the default configuration.""" | ||
| cfg = QuotaSchedulerConfiguration() | ||
| assert cfg is not None | ||
| # default value | ||
| assert cfg.period == 1 | ||
|
|
||
|
|
||
| def test_quota_scheduler_custom_configuration() -> None: | ||
| """Test the custom configuration.""" | ||
| cfg = QuotaSchedulerConfiguration(period=10) | ||
| assert cfg is not None | ||
| assert cfg.period == 10 | ||
Oops, something went wrong.
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.