-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test flakiness investigation and attempted fixes ❄ (#3498)
* Modifying two flaky animation tests, hopefully removing flakiness :) * Make switch_mode return an AwaitMount * Fix event issue * Add AwaitComplete - a more generalised optionally awaitable object * Use AwaitComplete in Tabs.remove_tab() and update tests accordingly. * Update TabbedContent to use AwaitComplete instead of AwaitTabbedContent * Simplifying - dont use optional awaitables where not required * Update variable name * Update a comment * Add watcher for cursor blink to ensure when blink is switched off, the cursor immediately becomes visible. Ensure we turn of cursor blink inside the input suggetions snapshot test. * Fix cursor blink reactive and disable cursor blink in the command palette snapshot test * More progress * Reworking AwaitComplete * Some more work on tabs flakiness/race-conditions * Ensure active tab is set correctly * Simplify next tab assignment * Simplify removing tabs logic * Make button animation duration configurable; Switch off button animation in snapshot test * Remove a flawed test * Add awaits in some tests * Docstrings * Make active_effect_duration an instance attribute * Fix a Tabs crash * Await the tree reload when the path changes in DirectoryTree * Change AwaitComplete _instances class attr to a set from a list * Make AwaitComplete generic, AwaitComplete._wait_all is now private, and exposes timeout parameter * Actually make AwaitComplete instances a set, not a list * Update CHANGELOG.md regarding flaky-test adjacent changes, AwaitComplete, etc.. * Remove whitespace * Use list() instead of useless comprehension, remove unused import * Ensure loading indicator _start_time is initialised correctly * Switch from time.sleep to asyncio.sleep in a notifications test, rework numbers to try and prevent flakiness * Resolve deadlock by awaiting event on the event loop instead of in the message pump * Renaming for clarity * Debugging for remove_tab test flakiness * Running all tests * Updating snapshots * Remove debugging prints * Fix broken docstring, remove unused import * Rename variable to make it clearer * Add missing return type annotation * Update src/textual/widgets/_tabbed_content.py Co-authored-by: Rodrigo Girão Serrão <[email protected]> * Update src/textual/widgets/_tabbed_content.py Co-authored-by: Rodrigo Girão Serrão <[email protected]> * Update src/textual/widgets/_tabs.py Co-authored-by: Rodrigo Girão Serrão <[email protected]> * Scroll datatable cursor after refresh * Add comment explaining use of call_after_refresh when scrolling data table cursor into view * Add repr to AwaitComplete (auto-repr_ * Remove use of generics from AwaitComplete * Update changelog and improve docstring * Add a missing parameter from DirectoryTree.reset_node docstring. Signed-off-by: Darren Burns <[email protected]> * Improve docstring in DirectoryTree Signed-off-by: Darren Burns <[email protected]> * Rename parameter coroutine to coroutines in await_complete.py, since it's a variable length param. --------- Signed-off-by: Darren Burns <[email protected]> Co-authored-by: Rodrigo Girão Serrão <[email protected]>
- Loading branch information
1 parent
5d7585c
commit 34fb596
Showing
19 changed files
with
332 additions
and
251 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from __future__ import annotations | ||
|
||
from asyncio import Future, gather | ||
from typing import Any, Coroutine, Iterator, TypeVar | ||
|
||
import rich.repr | ||
|
||
ReturnType = TypeVar("ReturnType") | ||
|
||
|
||
@rich.repr.auto(angular=True) | ||
class AwaitComplete: | ||
"""An 'optionally-awaitable' object.""" | ||
|
||
def __init__(self, *coroutines: Coroutine[Any, Any, Any]) -> None: | ||
"""Create an AwaitComplete. | ||
Args: | ||
coroutine: One or more coroutines to execute. | ||
""" | ||
self.coroutines = coroutines | ||
self._future: Future = gather(*self.coroutines) | ||
|
||
async def __call__(self) -> Any: | ||
return await self | ||
|
||
def __await__(self) -> Iterator[None]: | ||
return self._future.__await__() | ||
|
||
@property | ||
def is_done(self) -> bool: | ||
"""Returns True if the task has completed.""" | ||
return self._future.done() | ||
|
||
@property | ||
def exception(self) -> BaseException | None: | ||
"""An exception if it occurred in any of the coroutines.""" | ||
if self._future.done(): | ||
return self._future.exception() | ||
return None | ||
|
||
@classmethod | ||
def nothing(cls): | ||
"""Returns an already completed instance of AwaitComplete.""" | ||
instance = cls() | ||
instance._future = Future() | ||
instance._future.set_result(None) # Mark it as completed with no result | ||
return instance |
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.