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
Container Registry
Model registry
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
Maunium
synapse
Commits
48972ce9
Unverified
Commit
48972ce9
authored
6 years ago
by
Richard van der Hoff
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Patch defer.inlineCallbacks to check logcontexts in tests (#4205)
parent
a077e710
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
changelog.d/4205.misc
+1
-0
1 addition, 0 deletions
changelog.d/4205.misc
tests/__init__.py
+5
-2
5 additions, 2 deletions
tests/__init__.py
tests/patch_inline_callbacks.py
+90
-0
90 additions, 0 deletions
tests/patch_inline_callbacks.py
tests/unittest.py
+3
-1
3 additions, 1 deletion
tests/unittest.py
with
99 additions
and
3 deletions
changelog.d/4205.misc
0 → 100644
+
1
−
0
View file @
48972ce9
More logcontext checking in unittests
This diff is collapsed.
Click to expand it.
tests/__init__.py
+
5
−
2
View file @
48972ce9
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
...
...
@@ -15,7 +16,9 @@
from
twisted.trial
import
util
from
tests
import
utils
import
tests.patch_inline_callbacks
# attempt to do the patch before we load any synapse code
tests
.
patch_inline_callbacks
.
do_patch
()
util
.
DEFAULT_TIMEOUT_DURATION
=
10
utils
.
setupdb
()
This diff is collapsed.
Click to expand it.
tests/patch_inline_callbacks.py
0 → 100644
+
90
−
0
View file @
48972ce9
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
functools
import
sys
from
twisted.internet
import
defer
from
twisted.internet.defer
import
Deferred
from
twisted.python.failure
import
Failure
def
do_patch
():
"""
Patch defer.inlineCallbacks so that it checks the state of the logcontext on exit
"""
from
synapse.util.logcontext
import
LoggingContext
orig_inline_callbacks
=
defer
.
inlineCallbacks
def
new_inline_callbacks
(
f
):
orig
=
orig_inline_callbacks
(
f
)
@functools.wraps
(
f
)
def
wrapped
(
*
args
,
**
kwargs
):
start_context
=
LoggingContext
.
current_context
()
try
:
res
=
orig
(
*
args
,
**
kwargs
)
except
Exception
:
if
LoggingContext
.
current_context
()
!=
start_context
:
err
=
"
%s changed context from %s to %s on exception
"
%
(
f
,
start_context
,
LoggingContext
.
current_context
()
)
print
(
err
,
file
=
sys
.
stderr
)
raise
Exception
(
err
)
raise
if
not
isinstance
(
res
,
Deferred
)
or
res
.
called
:
if
LoggingContext
.
current_context
()
!=
start_context
:
err
=
"
%s changed context from %s to %s
"
%
(
f
,
start_context
,
LoggingContext
.
current_context
()
)
# print the error to stderr because otherwise all we
# see in travis-ci is the 500 error
print
(
err
,
file
=
sys
.
stderr
)
raise
Exception
(
err
)
return
res
if
LoggingContext
.
current_context
()
!=
LoggingContext
.
sentinel
:
err
=
(
"
%s returned incomplete deferred in non-sentinel context
"
"
%s (start was %s)
"
)
%
(
f
,
LoggingContext
.
current_context
(),
start_context
,
)
print
(
err
,
file
=
sys
.
stderr
)
raise
Exception
(
err
)
def
check_ctx
(
r
):
if
LoggingContext
.
current_context
()
!=
start_context
:
err
=
"
%s completion of %s changed context from %s to %s
"
%
(
"
Failure
"
if
isinstance
(
r
,
Failure
)
else
"
Success
"
,
f
,
start_context
,
LoggingContext
.
current_context
(),
)
print
(
err
,
file
=
sys
.
stderr
)
raise
Exception
(
err
)
return
r
res
.
addBoth
(
check_ctx
)
return
res
return
wrapped
defer
.
inlineCallbacks
=
new_inline_callbacks
This diff is collapsed.
Click to expand it.
tests/unittest.py
+
3
−
1
View file @
48972ce9
...
...
@@ -34,7 +34,9 @@ from synapse.types import UserID, create_requester
from
synapse.util.logcontext
import
LoggingContext
,
LoggingContextFilter
from
tests.server
import
get_clock
,
make_request
,
render
,
setup_test_homeserver
from
tests.utils
import
default_config
from
tests.utils
import
default_config
,
setupdb
setupdb
()
# Set up putting Synapse's logs into Trial's.
rootLogger
=
logging
.
getLogger
()
...
...
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