Commit 29c984ed authored by Denis Bilenko's avatar Denis Bilenko

update the existing test to work with the new Timeout

parent 631d7761
......@@ -87,8 +87,8 @@ class TestEvent(TestCase):
self.assertRaises(RuntimeError, evt.wait)
evt.reset()
# shouldn't see the RuntimeError again
gevent.Timeout(0.001, gevent.TimeoutError('from test_double_exception'))
self.assertRaises(gevent.TimeoutError, evt.wait)
gevent.Timeout(0.001, ValueError('from test_double_exception'))
self.assertRaises(ValueError, evt.wait)
if __name__ == '__main__':
......
......@@ -48,7 +48,7 @@ class Test(greentest.TestCase):
def test_nested_with_timeout(self):
def func():
return gevent.with_timeout(0.2, gevent.sleep, 2, timeout_value=1)
self.assertRaises(gevent.TimeoutError, gevent.with_timeout, 0.1, func)
self.assertRaises(gevent.Timeout, gevent.with_timeout, 0.1, func)
class TestTimers(greentest.TestCase):
......
......@@ -24,7 +24,7 @@ import sys
import greentest
import weakref
import time
from gevent import sleep, Timeout, TimeoutError
from gevent import sleep, Timeout
from gevent.greenlet import _SilentException
DELAY = 0.04
......@@ -35,18 +35,22 @@ class Test(greentest.TestCase):
def test_api(self):
# Nothing happens if with-block finishes before the timeout expires
with Timeout(DELAY*2):
t = Timeout(DELAY*2)
assert t.pending, repr(t)
with t:
sleep(DELAY)
sleep(DELAY*2) # check if timer was actually cancelled
# check if timer was actually cancelled
assert not t.pending, repr(t)
sleep(DELAY*2)
# An exception will be raised if it's not
try:
with Timeout(DELAY):
with Timeout(DELAY) as t:
sleep(DELAY*2)
except TimeoutError:
pass
except Timeout, ex:
assert ex is t, (ex, t)
else:
raise AssertionError('must raise TimeoutError')
raise AssertionError('must raise Timeout')
# You can customize the exception raised:
try:
......
......@@ -21,7 +21,7 @@ class TestQueue(TestCase):
def test_send_last(self):
q = coros.Queue()
def waiter(q):
timer = gevent.Timeout(0.1, gevent.TimeoutError)
timer = gevent.Timeout(0.1)
self.assertEquals(q.wait(), 'hi2')
timer.cancel()
......@@ -90,12 +90,12 @@ class TestQueue(TestCase):
results = set()
def collect_pending_results():
for i, e in enumerate(evts):
timer = gevent.Timeout(0.001, gevent.TimeoutError)
timer = gevent.Timeout(0.001)
try:
x = e.wait()
results.add(x)
timer.cancel()
except gevent.TimeoutError:
except gevent.Timeout:
pass # no pending result at that event
return len(results)
q.send(sendings[0])
......
......@@ -21,7 +21,7 @@
import sys
import greentest
from gevent import sleep, with_timeout, TimeoutError, getcurrent
from gevent import sleep, with_timeout, Timeout, getcurrent
from gevent import proc, coros
DELAY = 0.01
......@@ -35,10 +35,10 @@ class TestLink_Signal(greentest.TestCase):
s = proc.Source()
q1, q2, q3 = coros.Queue(), coros.Queue(), coros.Queue()
s.link_value(q1)
self.assertRaises(TimeoutError, s.wait, 0)
self.assertRaises(Timeout, s.wait, 0)
assert s.wait(0, None) is None
assert s.wait(0.001, None) is None
self.assertRaises(TimeoutError, s.wait, 0.001)
self.assertRaises(Timeout, s.wait, 0.001)
s.send(1)
assert not q1.ready()
assert s.wait()==1
......
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