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
c674216c
Commit
c674216c
authored
Nov 08, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test_hub_join_timeout to real test and correct naming.
parent
7fb55e27
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
120 additions
and
100 deletions
+120
-100
src/gevent/testing/testcase.py
src/gevent/testing/testcase.py
+19
-0
src/gevent/tests/test__hub_join_timeout.py
src/gevent/tests/test__hub_join_timeout.py
+98
-0
src/gevent/tests/test_hub_join_timeout.py
src/gevent/tests/test_hub_join_timeout.py
+0
-99
src/gevent/tests/tests_that_dont_do_leakchecks.txt
src/gevent/tests/tests_that_dont_do_leakchecks.txt
+1
-0
src/gevent/tests/tests_that_dont_monkeypatch.txt
src/gevent/tests/tests_that_dont_monkeypatch.txt
+1
-0
src/gevent/tests/tests_that_dont_use_resolver.txt
src/gevent/tests/tests_that_dont_use_resolver.txt
+1
-1
No files found.
src/gevent/testing/testcase.py
View file @
c674216c
...
...
@@ -20,7 +20,9 @@
from
__future__
import
absolute_import
,
print_function
,
division
import
sys
from
time
import
time
import
os.path
from
contextlib
import
contextmanager
from
unittest
import
TestCase
as
BaseTestCase
from
functools
import
wraps
...
...
@@ -51,6 +53,23 @@ class TimeAssertMixin(object):
self
.
assertLessEqual
(
time_taken
,
max_time
)
self
.
assertGreaterEqual
(
time_taken
,
min_time
)
@
contextmanager
def
runs_in_given_time
(
self
,
expected
,
fuzzy
=
None
):
if
fuzzy
is
None
:
if
sysinfo
.
EXPECT_POOR_TIMER_RESOLUTION
or
sysinfo
.
LIBUV
:
# The noted timer jitter issues on appveyor/pypy3
fuzzy
=
expected
*
5.0
else
:
fuzzy
=
expected
/
2.0
start
=
time
()
yield
elapsed
=
time
()
-
start
self
.
assertTimeWithinRange
(
elapsed
,
expected
-
fuzzy
,
expected
+
fuzzy
)
def
runs_in_no_time
(
self
,
fuzzy
=
(
0.001
if
not
sysinfo
.
EXPECT_POOR_TIMER_RESOLUTION
and
not
sysinfo
.
LIBUV
else
1.0
)):
return
self
.
runs_in_given_time
(
0.0
,
fuzzy
)
def
_wrap_timeout
(
timeout
,
method
):
...
...
src/gevent/tests/test__hub_join_timeout.py
0 → 100644
View file @
c674216c
import
functools
import
unittest
import
gevent
import
gevent.core
from
gevent.event
import
Event
from
gevent.testing.testcase
import
TimeAssertMixin
from
gevent.testing.timing
import
SMALL_TICK
# setting up signal does not affect join()
gevent
.
signal
(
1
,
lambda
:
None
)
# wouldn't work on windows
def
repeated
(
func
,
repetitions
=
2
):
@
functools
.
wraps
(
func
)
def
f
(
self
):
for
_
in
range
(
repetitions
):
func
(
self
)
return
f
class
Test
(
TimeAssertMixin
,
unittest
.
TestCase
):
@
repeated
def
test_callback
(
self
):
# exiting because the spawned greenlet finished execution (spawn (=callback) variant)
x
=
gevent
.
spawn
(
lambda
:
5
)
with
self
.
runs_in_no_time
():
result
=
gevent
.
wait
(
timeout
=
10
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
x
.
dead
,
x
)
self
.
assertEqual
(
x
.
value
,
5
)
@
repeated
def
test_later
(
self
):
# exiting because the spawned greenlet finished execution (spawn_later (=timer) variant)
x
=
gevent
.
spawn_later
(
SMALL_TICK
,
lambda
:
5
)
with
self
.
runs_in_given_time
(
SMALL_TICK
):
result
=
gevent
.
wait
(
timeout
=
10
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
x
.
dead
,
x
)
@
repeated
def
test_timeout
(
self
):
# exiting because of timeout (the spawned greenlet still runs)
x
=
gevent
.
spawn_later
(
10
,
lambda
:
5
)
with
self
.
runs_in_given_time
(
SMALL_TICK
):
result
=
gevent
.
wait
(
timeout
=
SMALL_TICK
)
self
.
assertFalse
(
result
)
self
.
assertFalse
(
x
.
dead
,
x
)
x
.
kill
()
with
self
.
runs_in_no_time
():
result
=
gevent
.
wait
()
self
.
assertTrue
(
result
)
@
repeated
def
test_event
(
self
):
# exiting because of event (the spawned greenlet still runs)
x
=
gevent
.
spawn_later
(
10
,
lambda
:
5
)
event
=
Event
()
event_set
=
gevent
.
spawn_later
(
SMALL_TICK
,
event
.
set
)
with
self
.
runs_in_given_time
(
SMALL_TICK
):
result
=
gevent
.
wait
([
event
])
self
.
assertEqual
(
result
,
[
event
])
self
.
assertFalse
(
x
.
dead
,
x
)
self
.
assertTrue
(
event_set
.
dead
)
self
.
assertTrue
(
event
.
is_set
)
x
.
kill
()
with
self
.
runs_in_no_time
():
result
=
gevent
.
wait
()
self
.
assertTrue
(
result
)
@
repeated
def
test_ref_arg
(
self
):
# checking "ref=False" argument
gevent
.
get_hub
().
loop
.
timer
(
10
,
ref
=
False
).
start
(
lambda
:
None
)
with
self
.
runs_in_no_time
():
result
=
gevent
.
wait
()
self
.
assertTrue
(
result
)
@
repeated
def
test_ref_attribute
(
self
):
# checking "ref=False" attribute
w
=
gevent
.
get_hub
().
loop
.
timer
(
10
)
w
.
start
(
lambda
:
None
)
w
.
ref
=
False
with
self
.
runs_in_no_time
():
result
=
gevent
.
wait
()
self
.
assertTrue
(
result
)
class
TestAgain
(
Test
):
"Repeat the same tests"
if
__name__
==
'__main__'
:
unittest
.
main
()
src/gevent/tests/test_hub_join_timeout.py
deleted
100644 → 0
View file @
7fb55e27
from
contextlib
import
contextmanager
import
gevent
import
gevent.core
from
gevent.event
import
Event
from
time
import
time
from
gevent.testing.six
import
xrange
SMALL
=
0.1
FUZZY
=
SMALL
/
2
# setting up signal does not affect join()
gevent
.
signal
(
1
,
lambda
:
None
)
# wouldn't work on windows
from
gevent.testing
import
EXPECT_POOR_TIMER_RESOLUTION
EXPECT_POOR_TIMER_RESOLUTION
=
EXPECT_POOR_TIMER_RESOLUTION
or
hasattr
(
gevent
.
core
,
'libuv'
)
# We observe longer/jittery timeouts running on appveyor or running with libuv
@
contextmanager
def
expected_time
(
expected
,
fuzzy
=
None
):
if
fuzzy
is
None
:
if
EXPECT_POOR_TIMER_RESOLUTION
:
# The noted timer jitter issues on appveyor/pypy3
fuzzy
=
expected
*
5.0
else
:
fuzzy
=
expected
/
2.0
start
=
time
()
yield
elapsed
=
time
()
-
start
assert
expected
-
fuzzy
<=
elapsed
<=
expected
+
fuzzy
,
'Expected: %r; elapsed: %r; fuzzy %r'
%
(
expected
,
elapsed
,
fuzzy
)
def
no_time
(
fuzzy
=
(
0.001
if
not
EXPECT_POOR_TIMER_RESOLUTION
else
1.0
)):
return
expected_time
(
0
,
fuzzy
=
fuzzy
)
for
_a
in
xrange
(
2
):
# exiting because the spawned greenlet finished execution (spawn (=callback) variant)
for
_
in
xrange
(
2
):
x
=
gevent
.
spawn
(
lambda
:
5
)
with
no_time
(
SMALL
):
result
=
gevent
.
wait
(
timeout
=
10
)
assert
result
is
True
,
repr
(
result
)
assert
x
.
dead
,
x
assert
x
.
value
==
5
,
x
# exiting because the spawned greenlet finished execution (spawn_later (=timer) variant)
for
_
in
xrange
(
2
):
x
=
gevent
.
spawn_later
(
SMALL
,
lambda
:
5
)
with
expected_time
(
SMALL
):
result
=
gevent
.
wait
(
timeout
=
10
)
assert
result
is
True
,
repr
(
result
)
assert
x
.
dead
,
x
# exiting because of timeout (the spawned greenlet still runs)
for
_
in
xrange
(
2
):
x
=
gevent
.
spawn_later
(
10
,
lambda
:
5
)
with
expected_time
(
SMALL
):
result
=
gevent
.
wait
(
timeout
=
SMALL
)
assert
result
is
False
,
repr
(
result
)
assert
not
x
.
dead
,
(
x
,
x
.
_start_event
)
x
.
kill
()
with
no_time
():
result
=
gevent
.
wait
()
assert
result
is
True
# exiting because of event (the spawned greenlet still runs)
for
_
in
xrange
(
2
):
x
=
gevent
.
spawn_later
(
10
,
lambda
:
5
)
event
=
Event
()
event_set
=
gevent
.
spawn_later
(
SMALL
,
event
.
set
)
with
expected_time
(
SMALL
):
result
=
gevent
.
wait
([
event
])
assert
result
==
[
event
],
repr
(
result
)
assert
not
x
.
dead
,
x
assert
event_set
.
dead
assert
event
.
is_set
()
x
.
kill
()
with
no_time
():
result
=
gevent
.
wait
()
assert
result
is
True
# checking "ref=False" argument
for
_
in
xrange
(
2
):
gevent
.
get_hub
().
loop
.
timer
(
10
,
ref
=
False
).
start
(
lambda
:
None
)
with
no_time
():
result
=
gevent
.
wait
()
assert
result
is
True
# checking "ref=False" attribute
for
_d
in
xrange
(
2
):
w
=
gevent
.
get_hub
().
loop
.
timer
(
10
)
w
.
start
(
lambda
:
None
)
w
.
ref
=
False
with
no_time
():
result
=
gevent
.
wait
()
assert
result
is
True
src/gevent/tests/tests_that_dont_do_leakchecks.txt
View file @
c674216c
...
...
@@ -5,3 +5,4 @@ test__monkey_scope.py
test__ares_timeout.py
test__close_backend_fd.py
test__hub_join.py
test__hub_join_timeout.py
src/gevent/tests/tests_that_dont_monkeypatch.txt
View file @
c674216c
...
...
@@ -23,3 +23,4 @@ test__iwait.py
test__ares_timeout.py
test__close_backend_fd.py
test__hub_join.py
test__hub_join_timeout.py
src/gevent/tests/tests_that_dont_use_resolver.txt
View file @
c674216c
...
...
@@ -31,7 +31,7 @@ test__greenlet.py
test__greenletset.py
# uses socket test__greenness.py
test__hub_join.py
test_hub_join_timeout.py
test_
_
hub_join_timeout.py
# uses socket test__hub.py
test_issue112.py
test__joinall.py
...
...
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