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
9e6e12f5
Commit
9e6e12f5
authored
Aug 10, 2009
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test__queue.py: use the new Event class
parent
abf28316
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
27 deletions
+28
-27
greentest/test__queue.py
greentest/test__queue.py
+28
-27
No files found.
greentest/test__queue.py
View file @
9e6e12f5
from
greentest
import
TestCase
,
main
import
gevent
from
gevent
import
util
,
cor
os
,
cor
e
from
gevent
import
util
,
core
from
gevent
import
queue
from
gevent.event
import
Event
class
TestQueue
(
TestCase
):
...
...
@@ -55,21 +56,21 @@ class TestQueue(TestCase):
q
=
queue
.
Queue
(
0
)
def
sender
(
evt
,
q
):
q
.
put
(
'hi'
)
evt
.
send
(
'done'
)
evt
.
put
(
'done'
)
def
receiver
(
evt
,
q
):
x
=
q
.
get
()
evt
.
send
(
x
)
evt
.
put
(
x
)
e1
=
coros
.
e
vent
()
e2
=
coros
.
e
vent
()
e1
=
E
vent
()
e2
=
E
vent
()
p1
=
gevent
.
spawn
(
sender
,
e1
,
q
)
gevent
.
sleep
(
0.001
)
self
.
assert_
(
not
e1
.
ready
())
p2
=
gevent
.
spawn
(
receiver
,
e2
,
q
)
self
.
assertEquals
(
e2
.
wai
t
(),
'hi'
)
self
.
assertEquals
(
e1
.
wai
t
(),
'done'
)
self
.
assertEquals
(
e2
.
ge
t
(),
'hi'
)
self
.
assertEquals
(
e1
.
ge
t
(),
'done'
)
timeout
=
gevent
.
Timeout
(
0
)
try
:
gevent
.
joinall
([
p1
,
p2
])
...
...
@@ -81,10 +82,10 @@ class TestQueue(TestCase):
q
=
queue
.
Queue
()
def
waiter
(
q
,
evt
):
evt
.
send
(
q
.
get
())
evt
.
put
(
q
.
get
())
sendings
=
[
'1'
,
'2'
,
'3'
,
'4'
]
evts
=
[
coros
.
e
vent
()
for
x
in
sendings
]
evts
=
[
E
vent
()
for
x
in
sendings
]
for
i
,
x
in
enumerate
(
sendings
):
gevent
.
spawn
(
waiter
,
q
,
evts
[
i
])
# use waitall for them
...
...
@@ -95,7 +96,7 @@ class TestQueue(TestCase):
for
i
,
e
in
enumerate
(
evts
):
timer
=
gevent
.
Timeout
(
0.001
)
try
:
x
=
e
.
wai
t
()
x
=
e
.
ge
t
()
results
.
add
(
x
)
timer
.
cancel
()
except
gevent
.
Timeout
:
...
...
@@ -116,13 +117,13 @@ class TestQueue(TestCase):
gevent
.
Timeout
(
0
,
RuntimeError
())
try
:
result
=
q
.
get
()
evt
.
send
(
result
)
evt
.
put
(
result
)
except
RuntimeError
:
evt
.
send
(
'timed out'
)
evt
.
put
(
'timed out'
)
evt
=
coros
.
e
vent
()
evt
=
E
vent
()
gevent
.
spawn
(
do_receive
,
q
,
evt
)
self
.
assertEquals
(
evt
.
wai
t
(),
'timed out'
)
self
.
assertEquals
(
evt
.
ge
t
(),
'timed out'
)
q
.
put
(
'hi'
)
self
.
assertEquals
(
q
.
get
(),
'hi'
)
...
...
@@ -138,47 +139,47 @@ class TestQueue(TestCase):
def
test_two_waiters_one_dies
(
self
):
def
waiter
(
q
,
evt
):
evt
.
send
(
q
.
get
())
evt
.
put
(
q
.
get
())
def
do_receive
(
q
,
evt
):
timeout
=
gevent
.
Timeout
(
0
,
RuntimeError
())
try
:
try
:
result
=
q
.
get
()
evt
.
send
(
result
)
evt
.
put
(
result
)
except
RuntimeError
:
evt
.
send
(
'timed out'
)
evt
.
put
(
'timed out'
)
finally
:
timeout
.
cancel
()
q
=
queue
.
Queue
()
dying_evt
=
coros
.
e
vent
()
waiting_evt
=
coros
.
e
vent
()
dying_evt
=
E
vent
()
waiting_evt
=
E
vent
()
gevent
.
spawn
(
do_receive
,
q
,
dying_evt
)
gevent
.
spawn
(
waiter
,
q
,
waiting_evt
)
gevent
.
sleep
(
0
)
q
.
put
(
'hi'
)
self
.
assertEquals
(
dying_evt
.
wai
t
(),
'timed out'
)
self
.
assertEquals
(
waiting_evt
.
wai
t
(),
'hi'
)
self
.
assertEquals
(
dying_evt
.
ge
t
(),
'timed out'
)
self
.
assertEquals
(
waiting_evt
.
ge
t
(),
'hi'
)
def
test_two_bogus_waiters
(
self
):
def
do_receive
(
q
,
evt
):
gevent
.
Timeout
(
0
,
RuntimeError
())
try
:
result
=
q
.
get
()
evt
.
send
(
result
)
evt
.
put
(
result
)
except
RuntimeError
:
evt
.
send
(
'timed out'
)
evt
.
put
(
'timed out'
)
# XXX finally = timeout
q
=
queue
.
Queue
()
e1
=
coros
.
e
vent
()
e2
=
coros
.
e
vent
()
e1
=
E
vent
()
e2
=
E
vent
()
gevent
.
spawn
(
do_receive
,
q
,
e1
)
gevent
.
spawn
(
do_receive
,
q
,
e2
)
gevent
.
sleep
(
0
)
q
.
put
(
'sent'
)
self
.
assertEquals
(
e1
.
wai
t
(),
'timed out'
)
self
.
assertEquals
(
e2
.
wai
t
(),
'timed out'
)
self
.
assertEquals
(
e1
.
ge
t
(),
'timed out'
)
self
.
assertEquals
(
e2
.
ge
t
(),
'timed out'
)
self
.
assertEquals
(
q
.
get
(),
'sent'
)
...
...
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