Commit 474a335f authored by Denis Bilenko's avatar Denis Bilenko

add a test case that timeout could started/cancelled more than once

--HG--
extra : transplant_source : D%99l00%7E%5D%EEBG%BB%2CSF%12%CE%8B%01PK
parent 24d931d4
import greentest import greentest
import gevent import gevent
from gevent.hub import get_hub
DELAY = 0.01 DELAY = 0.01
...@@ -23,6 +25,28 @@ class TestDirectRaise(greentest.TestCase): ...@@ -23,6 +25,28 @@ class TestDirectRaise(greentest.TestCase):
class Test(greentest.TestCase): class Test(greentest.TestCase):
def _test(self, timeout):
try:
get_hub().switch()
raise AssertionError('Must raise Timeout')
except gevent.Timeout, ex:
if ex is not timeout:
raise
def test(self):
timeout = gevent.Timeout(0.01)
timeout.start()
self._test(timeout)
timeout.start()
self._test(timeout)
def test_cancel(self):
timeout = gevent.Timeout(0.01)
timeout.start()
timeout.cancel()
gevent.sleep(0.02)
assert not timeout.pending, timeout
def test_with_timeout(self): def test_with_timeout(self):
self.assertRaises(gevent.Timeout, gevent.with_timeout, DELAY, gevent.sleep, DELAY * 2) self.assertRaises(gevent.Timeout, gevent.with_timeout, DELAY, gevent.sleep, DELAY * 2)
X = object() X = object()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment