-
Notifications
You must be signed in to change notification settings - Fork 402
Remove logcontext problems caused by awaiting raw deferLater(...)
#19058
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
Open
MadLittleMods
wants to merge
7
commits into
develop
Choose a base branch
from
madlittlemods/remove-deferLater-logcontext-problems
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+10
−7
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4cfb55
Fix logcontext problems in `tests/util/test_task_scheduler.py`
MadLittleMods e4a733f
Better conversion
MadLittleMods 37f8fc0
Remove `deferLater from other tests
MadLittleMods 08e66e3
Remove mentions of `deferLater`
MadLittleMods 1e1d092
Even better adaption `incomplete_d`
MadLittleMods da7fb0c
Add changelog
MadLittleMods 66f3b29
Fix lints
MadLittleMods 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 |
---|---|---|
|
@@ -20,9 +20,10 @@ | |
# | ||
from typing import List, Optional, Tuple | ||
|
||
from twisted.internet.task import deferLater | ||
from twisted.internet.defer import Deferred | ||
from twisted.internet.testing import MemoryReactor | ||
|
||
from synapse.logging.context import make_deferred_yieldable | ||
from synapse.server import HomeServer | ||
from synapse.types import JsonMapping, ScheduledTask, TaskStatus | ||
from synapse.util.clock import Clock | ||
|
@@ -87,7 +88,7 @@ async def _sleeping_task( | |
self, task: ScheduledTask | ||
) -> Tuple[TaskStatus, Optional[JsonMapping], Optional[str]]: | ||
# Sleep for a second | ||
await deferLater(self.reactor, 1, lambda: None) | ||
await self.hs.get_clock().sleep(1) | ||
return TaskStatus.COMPLETE, None, None | ||
|
||
def test_schedule_lot_of_tasks(self) -> None: | ||
|
@@ -170,8 +171,10 @@ async def _resumable_task( | |
return TaskStatus.COMPLETE, {"success": True}, None | ||
else: | ||
await self.task_scheduler.update_task(task.id, result={"in_progress": True}) | ||
# Create a deferred which we will never complete | ||
incomplete_d: Deferred = Deferred() | ||
# Await forever to simulate an aborted task because of a restart | ||
await deferLater(self.reactor, 2**16, lambda: None) | ||
await make_deferred_yieldable(incomplete_d) | ||
Comment on lines
+174
to
+177
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the goal is to wait forever, let's actually wait forever instead of |
||
# This should never been called | ||
return TaskStatus.ACTIVE, None, None | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have also fixed this by wrapping the deferred with
make_deferred_yieldable(...)
. (see our logcontext docsex.
await make_deferred_yieldable(deferLater(self.reactor, 1, lambda: None))
Instead, I've opted to replace all of our
deferLater
usage with more proper clock utilities that handle logcontext rules already.