Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
6374ca40
Commit
6374ca40
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Update
parent
132279a4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/patch_inline_callbacks.py
+15
-8
15 additions, 8 deletions
tests/patch_inline_callbacks.py
with
15 additions
and
8 deletions
tests/patch_inline_callbacks.py
+
15
−
8
View file @
6374ca40
...
...
@@ -15,7 +15,6 @@
from
__future__
import
print_function
import
inspect
import
functools
import
sys
...
...
@@ -32,6 +31,8 @@ def do_patch():
from
synapse.logging.context
import
LoggingContext
orig_inline_callbacks
=
defer
.
inlineCallbacks
if
hasattr
(
orig_inline_callbacks
,
"
patched_by_synapse
"
):
return
def
new_inline_callbacks
(
f
):
@functools.wraps
(
f
)
...
...
@@ -100,13 +101,20 @@ def do_patch():
return
wrapped
defer
.
inlineCallbacks
=
new_inline_callbacks
new_inline_callbacks
.
patched_by_synapse
=
True
def
_check_yield_points
(
f
,
changes
,
start_context
):
"""
Wraps a generator that is about to passed to defer.inlineCallbacks
checking that after every yield the log contexts are correct.
"""
from
synapse.logging.context
import
LoggingContext
@functools.wraps
(
f
)
def
check_yield_points_inner
(
*
args
,
**
kwargs
):
expected_context
=
start_context
gen
=
f
(
*
args
,
**
kwargs
)
last_yield_line_no
=
1
...
...
@@ -119,12 +127,13 @@ def _check_yield_points(f, changes, start_context):
else
:
d
=
gen
.
send
(
result
)
except
(
StopIteration
,
defer
.
_DefGen_Return
)
as
e
:
if
LoggingContext
.
current_context
()
!=
start
_context
:
if
LoggingContext
.
current_context
()
!=
expected
_context
:
# This happens when the context is lost sometime *after* the
# final yield and returning. E.g. we forgot to yield on a
# function that returns a deferred.
err
=
(
"
%s returned and changed context from %s to %s, in %s between %d and end of func
"
"
Function %r returned and changed context from %s to %s,
"
"
in %s between %d and end of func
"
%
(
f
.
__qualname__
,
start_context
,
...
...
@@ -134,7 +143,6 @@ def _check_yield_points(f, changes, start_context):
)
)
changes
.
append
(
err
)
# print(err, file=sys.stderr)
# raise Exception(err)
return
getattr
(
e
,
"
value
"
,
None
)
...
...
@@ -144,10 +152,8 @@ def _check_yield_points(f, changes, start_context):
result
=
Failure
(
e
)
frame
=
gen
.
gi_frame
if
frame
.
f_code
.
co_name
==
"
check_yield_points_inner
"
:
frame
=
inspect
.
getgeneratorlocals
(
gen
)[
"
gen
"
].
gi_frame
if
LoggingContext
.
current_context
()
!=
start
_context
:
if
LoggingContext
.
current_context
()
!=
expected
_context
:
# This happens because the context is lost sometime *after* the
# previous yield and *after* the current yield. E.g. the
# deferred we waited on didn't follow the rules, or we forgot to
...
...
@@ -164,9 +170,10 @@ def _check_yield_points(f, changes, start_context):
)
)
changes
.
append
(
err
)
# print(err, file=sys.stderr)
# raise Exception(err)
expected_context
=
LoggingContext
.
current_context
()
last_yield_line_no
=
frame
.
f_lineno
return
check_yield_points_inner
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment