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
60ef721a
Commit
60ef721a
authored
Aug 05, 2011
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extend test_hub_join_timeout.py to check "ref" property
parent
c97c60aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
12 deletions
+60
-12
greentest/test_hub_join_timeout.py
greentest/test_hub_join_timeout.py
+60
-12
No files found.
greentest/test_hub_join_timeout.py
View file @
60ef721a
from
__future__
import
with_statement
from
contextlib
import
contextmanager
import
gevent
from
time
import
time
...
...
@@ -5,21 +7,67 @@ from time import time
SMALL
=
0.1
FUZZY
=
SMALL
/
2
# setting up signal does not affect join()
gevent
.
signal
(
1
,
lambda
:
None
)
# wouldn't work on windows
@
contextmanager
def
expected_time
(
expected
,
fuzzy
=
None
):
if
fuzzy
is
None
:
fuzzy
=
expected
/
2.
start
=
time
()
yield
elapsed
=
time
()
-
start
assert
expected
-
fuzzy
<=
elapsed
<=
expected
+
fuzzy
,
'Expected: %r; elapsed: %r'
%
(
expected
,
elapsed
)
def
no_time
(
fuzzy
=
0.001
):
return
expected_time
(
0
,
fuzzy
=
fuzzy
)
for
_a
in
xrange
(
2
):
for
_b
in
xrange
(
2
):
gevent
.
spawn_later
(
SMALL
,
lambda
:
5
)
start
=
time
()
result
=
gevent
.
get_hub
().
join
(
timeout
=
10
)
# 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
.
get_hub
().
join
(
timeout
=
10
)
assert
result
is
True
,
repr
(
result
)
delay
=
time
()
-
start
assert
SMALL
-
FUZZY
<=
delay
<=
SMALL
+
FUZZY
,
delay
assert
x
.
dead
,
x
assert
x
.
value
==
5
,
x
for
_c
in
xrange
(
2
):
gevent
.
spawn_later
(
10
,
lambda
:
5
)
start
=
time
()
result
=
gevent
.
get_hub
().
join
(
timeout
=
SMALL
)
# 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
.
get_hub
().
join
(
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
.
get_hub
().
join
(
timeout
=
SMALL
)
assert
result
is
None
,
repr
(
result
)
delay
=
time
()
-
start
assert
SMALL
-
FUZZY
<=
delay
<=
SMALL
+
FUZZY
,
delay
assert
not
x
.
dead
,
x
x
.
kill
()
with
no_time
():
result
=
gevent
.
get_hub
().
join
()
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
.
get_hub
().
join
()
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
.
get_hub
().
join
()
assert
result
is
True
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