-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
118 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
46 changes: 46 additions & 0 deletions
46
src/tribler/core/components/restapi/rest/tests/test_rest_endpoint.py
This file contains 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,46 @@ | ||
from unittest.mock import AsyncMock, patch | ||
|
||
from tribler.core.components.restapi.rest.rest_endpoint import RESTEndpoint | ||
from tribler.core.utilities.async_group import AsyncGroup | ||
|
||
|
||
# pylint: disable=protected-access | ||
|
||
async def test_shutdown(): | ||
# In this test we check that all coros related to the Root Endpoint are cancelled | ||
# during shutdown | ||
|
||
async def coro(): | ||
... | ||
|
||
root_endpoint = RESTEndpoint() | ||
root_endpoint.async_group.add(coro()) | ||
|
||
# add 2 child endpoints with a single coro in each: | ||
child_endpoints = [RESTEndpoint(), RESTEndpoint()] | ||
for index, child_endpoint in enumerate(child_endpoints): | ||
root_endpoint.add_endpoint(prefix=f'/{index}', endpoint=child_endpoint) | ||
child_endpoint.async_group.add(coro()) | ||
|
||
def total_coro_count(): | ||
count = 0 | ||
for endpoint in child_endpoints + [root_endpoint]: | ||
count += len(endpoint.async_group._futures) | ||
return count | ||
|
||
assert total_coro_count() == 3 | ||
|
||
await root_endpoint.shutdown() | ||
|
||
assert total_coro_count() == 0 | ||
|
||
|
||
@patch.object(AsyncGroup, 'cancel', new_callable=AsyncMock) | ||
async def test_multiple_shutdown_calls(async_group_cancel: AsyncMock): | ||
# Test that if shutdown calls twice, only one call is processed | ||
endpoint = RESTEndpoint() | ||
|
||
await endpoint.shutdown() | ||
await endpoint.shutdown() | ||
|
||
async_group_cancel.assert_called_once() |
This file contains 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 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 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 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 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