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
135c33f0
Commit
135c33f0
authored
Apr 22, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test__greenlet.py: add TestBasic
parent
fddad38c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
145 additions
and
19 deletions
+145
-19
greentest/test__greenlet.py
greentest/test__greenlet.py
+145
-19
No files found.
greentest/test__greenlet.py
View file @
135c33f0
...
...
@@ -516,28 +516,154 @@ class TestJoinAll(greentest.GenericWaitTestCase):
gevent
.
joinall
([
gevent
.
spawn
(
gevent
.
sleep
,
10
)],
timeout
=
timeout
)
class
TestKill
(
greentest
.
TestCase
):
class
TestBasic
(
greentest
.
TestCase
):
def
test_simple_exit
(
self
):
link_test
=
[]
def
func
(
delay
,
return_value
=
4
):
gevent
.
sleep
(
delay
)
return
return_value
g
=
gevent
.
Greenlet
(
func
,
0.01
,
return_value
=
5
)
g
.
link
(
lambda
x
:
link_test
.
append
(
x
))
assert
not
g
assert
not
g
.
dead
assert
not
g
.
started
assert
not
g
.
ready
()
assert
not
g
.
successful
()
assert
g
.
value
is
None
assert
g
.
exception
is
None
g
.
start
()
assert
not
g
assert
not
g
.
dead
assert
g
.
started
# changed
assert
not
g
.
ready
()
assert
not
g
.
successful
()
assert
g
.
value
is
None
assert
g
.
exception
is
None
def
test_kill_running
(
self
):
g
=
gevent
.
spawn
(
gevent
.
sleep
,
10
)
gevent
.
sleep
(
0.001
)
error
=
ExpectedError
(
'hello world'
)
g
.
kill
(
error
)
gevent
.
sleep
(
0.01
)
assert
g
.
dead
,
g
.
dead
assert
g
# changed
assert
not
g
.
dead
assert
g
.
started
assert
not
g
.
ready
()
assert
not
g
.
successful
()
assert
g
.
value
is
None
assert
g
.
exception
is
None
assert
not
link_test
gevent
.
sleep
(
0.02
)
assert
not
g
assert
g
.
dead
assert
not
g
.
started
assert
g
.
ready
()
assert
g
.
successful
()
assert
g
.
value
==
5
assert
g
.
exception
is
None
# not changed
assert
link_test
==
[
g
]
# changed
def
test_error_exit
(
self
):
link_test
=
[]
def
func
(
delay
,
return_value
=
4
):
gevent
.
sleep
(
delay
)
error
=
ExpectedError
(
'test_error_exit'
)
error
.
myattr
=
return_value
raise
error
g
=
gevent
.
Greenlet
(
func
,
0.01
,
return_value
=
5
)
g
.
link
(
lambda
x
:
link_test
.
append
(
x
))
g
.
start
()
gevent
.
sleep
(
0.02
)
assert
not
g
assert
g
.
dead
assert
not
g
.
started
assert
g
.
ready
()
assert
g
.
exception
is
error
,
(
g
.
exception
,
error
)
#def test_kill_not_started(self): # currently kill() does nothing if Greenlet is not yet started
def
test_kill_started_later
(
self
):
g
=
gevent
.
spawn_later
(
0.01
,
gevent
.
sleep
,
10
)
error
=
AssertionError
(
'this must must not be raised'
)
g
.
kill
(
error
)
gevent
.
sleep
(
0.1
)
assert
g
.
dead
,
g
assert
g
.
ready
(),
g
assert
g
.
exception
is
error
,
(
g
.
exception
,
error
)
assert
not
g
.
successful
()
assert
g
.
value
is
None
# not changed
assert
g
.
exception
.
myattr
==
5
assert
link_test
==
[
g
],
link_test
def
_assertKilled
(
self
,
g
):
assert
not
g
assert
g
.
dead
assert
not
g
.
started
assert
g
.
ready
()
assert
g
.
successful
(),
(
repr
(
g
),
g
.
value
,
g
.
exception
)
assert
isinstance
(
g
.
value
,
gevent
.
GreenletExit
),
(
repr
(
g
),
g
.
value
,
g
.
exception
)
assert
g
.
exception
is
None
def
assertKilled
(
self
,
g
):
self
.
_assertKilled
(
g
)
gevent
.
sleep
(
0.01
)
self
.
_assertKilled
(
g
)
def
_test_kill
(
self
,
g
,
block
):
g
.
kill
(
block
=
block
)
if
not
block
:
gevent
.
sleep
(
0.01
)
self
.
assertKilled
(
g
)
# kill second time must not hurt
g
.
kill
(
block
=
block
)
self
.
assertKilled
(
g
)
def
_test_kill_not_started
(
self
,
block
):
link_test
=
[]
result
=
[]
g
=
gevent
.
Greenlet
(
lambda
:
result
.
append
(
1
))
g
.
link
(
lambda
x
:
link_test
.
append
(
x
))
self
.
_test_kill
(
g
,
block
=
block
)
assert
not
result
assert
link_test
==
[
g
]
def
test_kill_not_started_block
(
self
):
self
.
_test_kill_not_started
(
block
=
True
)
def
test_kill_not_started_noblock
(
self
):
self
.
_test_kill_not_started
(
block
=
False
)
def
_test_kill_just_started
(
self
,
block
):
result
=
[]
link_test
=
[]
g
=
gevent
.
Greenlet
(
lambda
:
result
.
append
(
1
))
g
.
link
(
lambda
x
:
link_test
.
append
(
x
))
g
.
start
()
self
.
_test_kill
(
g
,
block
=
block
)
assert
not
result
,
result
assert
link_test
==
[
g
]
def
test_kill_just_started_block
(
self
):
self
.
_test_kill_just_started
(
block
=
True
)
def
test_kill_just_started_noblock
(
self
):
self
.
_test_kill_just_started
(
block
=
False
)
def
_test_kill_just_started_later
(
self
,
block
):
result
=
[]
link_test
=
[]
g
=
gevent
.
Greenlet
(
lambda
:
result
.
append
(
1
))
g
.
link
(
lambda
x
:
link_test
.
append
(
x
))
g
.
start_later
(
1
)
self
.
_test_kill
(
g
,
block
=
block
)
assert
not
result
def
test_kill_just_started_later_block
(
self
):
self
.
_test_kill_just_started_later
(
block
=
True
)
def
test_kill_just_started_later_noblock
(
self
):
self
.
_test_kill_just_started_later
(
block
=
False
)
def
_test_kill_running
(
self
,
block
):
link_test
=
[]
g
=
gevent
.
spawn
(
gevent
.
sleep
,
10
)
g
.
link
(
lambda
x
:
link_test
.
append
(
x
))
gevent
.
sleep
(
0.01
)
self
.
_test_kill
(
g
,
block
=
block
)
assert
link_test
==
[
g
]
def
test_kill_running_block
(
self
):
self
.
_test_kill_running
(
block
=
True
)
def
test_kill_running_noblock
(
self
):
self
.
_test_kill_running
(
block
=
False
)
def
assert_ready
(
g
):
...
...
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