Commit 72503017 authored by Denis Bilenko's avatar Denis Bilenko

add greentest.GenericWaitTestCase

parent cbfda28f
......@@ -24,6 +24,8 @@ import sys
import os
import errno
import unittest
import time
import gevent
disabled_marker = '-*-*-*-*-*- disabled -*-*-*-*-*-'
......@@ -92,3 +94,26 @@ class CountingHub(_original_Hub):
return _original_Hub.switch(self)
gevent.hub.Hub = CountingHub
class GenericWaitTestCase(TestCase):
def wait(self, timeout):
raise NotImplementedError('override me in subclass')
def test_outer_timeout_is_not_lost(self):
t = gevent.Timeout.start_new(0.01)
try:
self.wait(timeout=0.02)
except gevent.Timeout, ex:
assert ex is t, (ex, t)
else:
raise AssertionError('must raise Timeout')
gevent.sleep(0.02)
def test_returns_after_timeout(self):
start = time.time()
self.wait(timeout=0.01)
# join simply returns after timeout expires
delay = time.time() - start
assert 0.01 <= delay < 0.01 + 0.01, delay
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