Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #608 from sublee/fix-607
Fix 607
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# A greenlet that's killed with an exception should fail. | ||
import greentest | ||
import gevent | ||
|
||
|
||
class ExpectedError(greentest.ExpectedException): | ||
pass | ||
|
||
|
||
def f(): | ||
gevent.sleep(999) | ||
|
||
|
||
class TestKillWithException(greentest.TestCase): | ||
|
||
def test_kill_without_exception(self): | ||
g = gevent.spawn(f) | ||
g.kill() | ||
assert g.successful() | ||
assert isinstance(g.get(), gevent.GreenletExit) | ||
|
||
def test_kill_with_exception(self): | ||
# issue-607 pointed this case. | ||
g = gevent.spawn(f) | ||
g.kill(ExpectedError) | ||
assert not g.successful() | ||
self.assertRaises(ExpectedError, g.get) | ||
assert g.value is None | ||
assert isinstance(g.exception, ExpectedError) | ||
|
||
def test_kill_with_exception_after_started(self): | ||
g = gevent.spawn(f) | ||
g.join(0) | ||
g.kill(ExpectedError) | ||
assert not g.successful() | ||
self.assertRaises(ExpectedError, g.get) | ||
assert g.value is None | ||
assert isinstance(g.exception, ExpectedError) | ||
|
||
|
||
if __name__ == '__main__': | ||
greentest.main() |