-
Notifications
You must be signed in to change notification settings - Fork 32
🐛 fix webserver wallet exclusive queues are removed when they should not #7912
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
matusdrobuliak66
merged 19 commits into
ITISFoundation:master
from
matusdrobuliak66:bugfix/wrong-removal-of-exclusive-queues
Jun 17, 2025
Merged
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9cf273a
fix bug
matusdrobuliak66 2a1a8e2
fix bug
matusdrobuliak66 fcb831e
fix bug
matusdrobuliak66 20f83c7
Merge branch 'master' into bugfix/wrong-removal-of-exclusive-queues
matusdrobuliak66 2e56085
review @GitHK
matusdrobuliak66 1625254
Merge branch 'bugfix/wrong-removal-of-exclusive-queues' of github.com…
matusdrobuliak66 6a8401e
review @GitHK
matusdrobuliak66 87fbcf7
Merge branch 'master' into bugfix/wrong-removal-of-exclusive-queues
matusdrobuliak66 7b02c94
review @sanderegg
matusdrobuliak66 3fe2045
Merge branch 'bugfix/wrong-removal-of-exclusive-queues' of github.com…
matusdrobuliak66 ae33d6e
Merge branch 'master' into bugfix/wrong-removal-of-exclusive-queues
matusdrobuliak66 9d0dab4
pylint ignore
matusdrobuliak66 e0fff37
pylint ignore
matusdrobuliak66 4a6289a
Merge branch 'master' into bugfix/wrong-removal-of-exclusive-queues
matusdrobuliak66 6e85d35
pylint ignore
matusdrobuliak66 98b191d
review @pcrespov
matusdrobuliak66 f98dc07
defensive programming
matusdrobuliak66 2bb643f
Merge branch 'master' into bugfix/wrong-removal-of-exclusive-queues
matusdrobuliak66 6fad762
Merge branch 'master' into bugfix/wrong-removal-of-exclusive-queues
matusdrobuliak66 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
68 changes: 68 additions & 0 deletions
68
services/web/server/tests/unit/isolated/notifications/test_wallet_osparc_credits.py
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,68 @@ | ||
| # Unit tests for wallet_osparc_credits.py subscribe and unsubscribe functions | ||
| import asyncio | ||
| from unittest.mock import AsyncMock, patch | ||
|
|
||
| import pytest | ||
| from models_library.wallets import WalletID | ||
| from simcore_service_webserver.notifications import wallet_osparc_credits | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def app_with_wallets(): | ||
| app = { | ||
| "wallet_subscription_lock": asyncio.Lock(), | ||
| "wallet_subscriptions": {}, | ||
| } | ||
| return app | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def wallet_id(): | ||
| return WalletID(1) | ||
|
|
||
|
|
||
| async def test_subscribe_first_and_second(app_with_wallets, wallet_id): | ||
| app = app_with_wallets | ||
| app["wallet_subscriptions"][wallet_id] = 0 | ||
| mock_rabbit = AsyncMock() | ||
| with patch( | ||
| "simcore_service_webserver.notifications.wallet_osparc_credits.get_rabbitmq_client", | ||
| return_value=mock_rabbit, | ||
| ): | ||
| await wallet_osparc_credits.subscribe(app, wallet_id) | ||
| mock_rabbit.add_topics.assert_awaited_once() | ||
| # Second subscribe should not call add_topics again | ||
| await wallet_osparc_credits.subscribe(app, wallet_id) | ||
| assert mock_rabbit.add_topics.await_count == 1 | ||
| assert app["wallet_subscriptions"][wallet_id] == 2 | ||
|
|
||
|
|
||
| async def test_unsubscribe_last_and_not_last(app_with_wallets, wallet_id): | ||
| app = app_with_wallets | ||
| app["wallet_subscriptions"][wallet_id] = 2 | ||
| mock_rabbit = AsyncMock() | ||
| with patch( | ||
| "simcore_service_webserver.notifications.wallet_osparc_credits.get_rabbitmq_client", | ||
| return_value=mock_rabbit, | ||
| ): | ||
| # Not last unsubscribe | ||
| await wallet_osparc_credits.unsubscribe(app, wallet_id) | ||
| mock_rabbit.remove_topics.assert_not_awaited() | ||
| assert app["wallet_subscriptions"][wallet_id] == 1 | ||
| # Last unsubscribe | ||
| await wallet_osparc_credits.unsubscribe(app, wallet_id) | ||
| mock_rabbit.remove_topics.assert_awaited_once() | ||
| assert app["wallet_subscriptions"][wallet_id] == 0 | ||
|
|
||
|
|
||
| async def test_unsubscribe_when_not_subscribed(app_with_wallets, wallet_id): | ||
| app = app_with_wallets | ||
| # wallet_id not present | ||
| mock_rabbit = AsyncMock() | ||
| with patch( | ||
| "simcore_service_webserver.notifications.wallet_osparc_credits.get_rabbitmq_client", | ||
| return_value=mock_rabbit, | ||
| ): | ||
| await wallet_osparc_credits.unsubscribe(app, wallet_id) | ||
| mock_rabbit.remove_topics.assert_not_awaited() | ||
| assert app["wallet_subscriptions"].get(wallet_id, 0) == 0 |
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.