-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Handle connection errors (#524)
* Add some exception handling for gathered ConnectionErrors * Refactor length checks to be more pythonic * Add test for checking that broadcast_raw ignores ConnectionErrors * Use asyncio.as_completed to handle exceptions per future * Check weak references explicitly * Add test for gather_without_exceptions * Adjust test to check for ConnectionError's specifically * Fix gather_without_exception subclass behavior * Log at TRACE level during tests * Added a fixture for creating temporary users on demand * Test for generating connection errors * Handle all ConnectionErrors the same * Add weak reference check to broadcast_shutdown
- Loading branch information
Showing
12 changed files
with
273 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
Some helper functions for common async tasks. | ||
""" | ||
import asyncio | ||
from typing import Any, List | ||
|
||
|
||
async def gather_without_exceptions( | ||
tasks: List[asyncio.Task], | ||
*exceptions: type, | ||
) -> List[Any]: | ||
""" | ||
Call gather on a list of tasks, raising the first exception that dosen't | ||
match any of the specified exception classes. | ||
""" | ||
results = await asyncio.gather(*tasks, return_exceptions=True) | ||
for result in results: | ||
if isinstance(result, Exception): | ||
# Check if this exception is an instance (maybe subclass) that | ||
# should be ignored | ||
for exc_type in exceptions: | ||
if not isinstance(result, exc_type): | ||
raise result | ||
return results |
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
Oops, something went wrong.