Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
ecd1bd10
Commit
ecd1bd10
authored
Feb 13, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix an error in leakcheck that called setup and teardown too many times.
parent
236739e4
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
70 additions
and
49 deletions
+70
-49
src/greentest/greentest/__init__.py
src/greentest/greentest/__init__.py
+1
-0
src/greentest/greentest/leakcheck.py
src/greentest/greentest/leakcheck.py
+50
-40
src/greentest/greentest/skipping.py
src/greentest/greentest/skipping.py
+8
-4
src/greentest/greentest/timing.py
src/greentest/greentest/timing.py
+1
-0
src/greentest/test___example_servers.py
src/greentest/test___example_servers.py
+1
-1
src/greentest/test__core_timer.py
src/greentest/test__core_timer.py
+6
-2
src/greentest/test__socket.py
src/greentest/test__socket.py
+3
-2
No files found.
src/greentest/greentest/__init__.py
View file @
ecd1bd10
...
...
@@ -58,6 +58,7 @@ from greentest.sysinfo import CONN_ABORTED_ERRORS
from
greentest.skipping
import
skipOnWindows
from
greentest.skipping
import
skipOnAppVeyor
from
greentest.skipping
import
skipOnCI
from
greentest.skipping
import
skipOnPyPy3OnCI
from
greentest.skipping
import
skipOnPyPy
from
greentest.skipping
import
skipOnPyPy3
...
...
src/greentest/greentest/leakcheck.py
View file @
ecd1bd10
...
...
@@ -32,19 +32,15 @@ def ignores_leakcheck(func):
func
.
ignore_leakcheck
=
True
return
func
def
wrap_refcount
(
method
):
if
getattr
(
method
,
'ignore_leakcheck'
,
False
):
return
method
# Some builtin things that we ignore
IGNORED_TYPES
=
(
tuple
,
dict
,
types
.
FrameType
,
types
.
TracebackType
)
try
:
# Some builtin things that we ignore
IGNORED_TYPES
=
(
tuple
,
dict
,
types
.
FrameType
,
types
.
TracebackType
)
try
:
callback_kind
=
gevent
.
core
.
callback
except
AttributeError
:
except
AttributeError
:
# Must be using FFI.
from
gevent._ffi.callback
import
callback
as
callback_kind
def
type_hist
():
def
_
type_hist
():
d
=
collections
.
defaultdict
(
int
)
for
x
in
gc
.
get_objects
():
k
=
type
(
x
)
...
...
@@ -59,7 +55,7 @@ def wrap_refcount(method):
d
[
k
]
+=
1
return
d
def
report_diff
(
a
,
b
):
def
_
report_diff
(
a
,
b
):
diff_lines
=
[]
for
k
,
v
in
sorted
(
a
.
items
(),
key
=
lambda
i
:
i
[
0
].
__name__
):
if
b
[
k
]
!=
v
:
...
...
@@ -70,6 +66,11 @@ def wrap_refcount(method):
diff
=
'
\
n
'
.
join
(
diff_lines
)
return
diff
def
wrap_refcount
(
method
):
if
getattr
(
method
,
'ignore_leakcheck'
,
False
):
return
method
@
wraps
(
method
)
def
wrapper
(
self
,
*
args
,
**
kwargs
):
# pylint:disable=too-many-branches
gc
.
collect
()
...
...
@@ -78,25 +79,33 @@ def wrap_refcount(method):
deltas
=
[]
d
=
None
gc
.
disable
()
# The very first time we are called, we have already been
# self.setUp() by the test runner, so we don't need to do it again.
needs_setUp
=
False
try
:
while
True
:
# Grab current snapshot
hist_before
=
type_hist
()
hist_before
=
_
type_hist
()
d
=
sum
(
hist_before
.
values
())
if
needs_setUp
:
self
.
setUp
()
self
.
skipTearDown
=
False
try
:
method
(
self
,
*
args
,
**
kwargs
)
finally
:
self
.
tearDown
()
self
.
skipTearDown
=
True
needs_setUp
=
True
# Grab post snapshot
if
'urlparse'
in
sys
.
modules
:
sys
.
modules
[
'urlparse'
].
clear_cache
()
if
'urllib.parse'
in
sys
.
modules
:
sys
.
modules
[
'urllib.parse'
].
clear_cache
()
hist_after
=
type_hist
()
hist_after
=
_
type_hist
()
d
=
sum
(
hist_after
.
values
())
-
d
deltas
.
append
(
d
)
...
...
@@ -119,7 +128,7 @@ def wrap_refcount(method):
elif
len
(
deltas
)
>=
4
and
sum
(
deltas
[
-
4
:])
==
0
:
break
elif
len
(
deltas
)
>=
3
and
deltas
[
-
1
]
>
0
and
deltas
[
-
1
]
==
deltas
[
-
2
]
and
deltas
[
-
2
]
==
deltas
[
-
3
]:
diff
=
report_diff
(
hist_before
,
hist_after
)
diff
=
_
report_diff
(
hist_before
,
hist_after
)
raise
AssertionError
(
'refcount increased by %r
\
n
%s'
%
(
deltas
,
diff
))
# OK, we don't know for sure yet. Let's search for more
if
sum
(
deltas
[
-
3
:])
<=
0
or
sum
(
deltas
[
-
4
:])
<=
0
or
deltas
[
-
4
:].
count
(
0
)
>=
2
:
...
...
@@ -128,9 +137,10 @@ def wrap_refcount(method):
else
:
limit
=
7
if
len
(
deltas
)
>=
limit
:
raise
AssertionError
(
'refcount increased by %r
\
n
%s'
%
(
deltas
,
report_diff
(
hist_before
,
hist_after
)))
raise
AssertionError
(
'refcount increased by %r
\
n
%s'
%
(
deltas
,
_report_diff
(
hist_before
,
hist_after
)))
finally
:
gc
.
enable
()
self
.
skipTearDown
=
True
return
wrapper
src/greentest/greentest/skipping.py
View file @
ecd1bd10
...
...
@@ -23,13 +23,12 @@ import unittest
from
greentest
import
sysinfo
def
_identity
(
f
):
return
f
def
_do_not_skip
(
reason
):
assert
reason
def
dec
(
f
):
return
f
return
dec
return
_identity
if
sysinfo
.
WIN
:
...
...
@@ -50,6 +49,11 @@ if sysinfo.RUNNING_ON_APPVEYOR:
else
:
skipOnAppVeyor
=
_do_not_skip
if
sysinfo
.
RUNNING_ON_CI
:
skipOnCI
=
unittest
.
skip
else
:
skipOnCI
=
_do_not_skip
if
sysinfo
.
PYPY3
and
sysinfo
.
RUNNING_ON_CI
:
# Same as above, for PyPy3.3-5.5-alpha and 3.5-5.7.1-beta and 3.5-5.8
skipOnPyPy3OnCI
=
unittest
.
skip
...
...
src/greentest/greentest/timing.py
View file @
ecd1bd10
...
...
@@ -58,6 +58,7 @@ class _DelayWaitMixin(object):
# otherwise it's the raw number
seconds
=
getattr
(
timeout
,
'seconds'
,
timeout
)
gevent
.
get_hub
().
loop
.
update_now
()
start
=
time
.
time
()
try
:
result
=
self
.
wait
(
timeout
)
...
...
src/greentest/test___example_servers.py
View file @
ecd1bd10
...
...
@@ -101,7 +101,7 @@ class Test_wsgiserver_ssl(Test_wsgiserver):
ssl_ctx
=
ssl
.
_create_unverified_context
()
@
greentest
.
skipOn
LibuvOnCIOnPyPy
(
"Timing issues sometimes lead to a connection refused"
)
@
greentest
.
skipOn
CI
(
"Timing issues sometimes lead to a connection refused"
)
class
Test_webproxy
(
Test_wsgiserver
):
server
=
'webproxy.py'
...
...
src/greentest/test__core_timer.py
View file @
ecd1bd10
...
...
@@ -16,11 +16,15 @@ class Test(TestCase):
self
.
loop
=
config
.
loop
(
default
=
True
)
self
.
timer
=
self
.
loop
.
timer
(
0.001
,
repeat
=
self
.
repeat
)
def
tearDown
(
self
):
def
cleanup
(
self
):
# cleanup instead of tearDown to cooperate well with
# leakcheck.py
self
.
timer
.
close
()
# cycle the loop so libuv close callbacks fire
self
.
loop
.
run
()
self
.
loop
.
destroy
()
self
.
timer
=
None
self
.
loop
=
None
self
.
timer
=
None
def
f
(
self
,
x
=
None
):
self
.
called
.
append
(
1
)
...
...
src/greentest/test__socket.py
View file @
ecd1bd10
...
...
@@ -9,6 +9,7 @@ import unittest
import
greentest
from
functools
import
wraps
from
greentest
import
six
from
greentest
import
LARGE_TIMEOUT
# we use threading on purpose so that we can test both regular and gevent sockets with the same code
from
threading
import
Thread
as
_Thread
...
...
@@ -42,7 +43,7 @@ class TestTCP(greentest.TestCase):
__timeout__
=
None
TIMEOUT_ERROR
=
socket
.
timeout
long_data
=
", "
.
join
([
str
(
x
)
for
x
in
range
(
20000
)])
if
six
.
PY3
:
if
not
isinstance
(
long_data
,
bytes
)
:
long_data
=
long_data
.
encode
(
'ascii'
)
def
setUp
(
self
):
...
...
@@ -341,7 +342,7 @@ def get_port():
class
TestCreateConnection
(
greentest
.
TestCase
):
__timeout__
=
5
__timeout__
=
LARGE_TIMEOUT
def
test_refuses
(
self
):
with
self
.
assertRaises
(
socket
.
error
)
as
cm
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment