Commit 1bf73783 authored by Denis Bilenko's avatar Denis Bilenko

test__greenlet.py: update to pass totalrefcount check

parent d2eafe8a
...@@ -174,9 +174,9 @@ class LinksTestCase(greentest.TestCase): ...@@ -174,9 +174,9 @@ class LinksTestCase(greentest.TestCase):
def link(self, p, listener=None): def link(self, p, listener=None):
getattr(p, self.link_method)(listener) getattr(p, self.link_method)(listener)
def tearDown(self): def receiverf(self, proc_flag):
greentest.TestCase.tearDown(self) sleep(DELAY)
self.p.unlink() proc_flag.append('finished')
def set_links(self, p, first_time, kill_exc_type): def set_links(self, p, first_time, kill_exc_type):
event = AsyncResult() event = AsyncResult()
...@@ -184,11 +184,7 @@ class LinksTestCase(greentest.TestCase): ...@@ -184,11 +184,7 @@ class LinksTestCase(greentest.TestCase):
proc_flag = [] proc_flag = []
def receiver(): receiver = gevent.spawn(self.receiverf, proc_flag)
sleep(DELAY)
proc_flag.append('finished')
receiver = gevent.spawn(receiver)
self.link(p, receiver) self.link(p, receiver)
queue = Queue(1) queue = Queue(1)
...@@ -208,21 +204,21 @@ class LinksTestCase(greentest.TestCase): ...@@ -208,21 +204,21 @@ class LinksTestCase(greentest.TestCase):
for _ in range(10): for _ in range(10):
self.link(p, AsyncResult()) self.link(p, AsyncResult())
self.link(p, Queue(1).put) self.link(p, Queue(1).put)
return event, receiver, proc_flag, queue, callback_flag return event, receiver, proc_flag, queue, callback_flag
def myprocf(self, proc_finished_flag):
sleep(10)
proc_finished_flag.append('finished')
return 555
def set_links_timeout(self, link): def set_links_timeout(self, link):
# stuff that won't be touched # stuff that won't be touched
event = AsyncResult() event = AsyncResult()
link(event) link(event)
proc_finished_flag = [] proc_finished_flag = []
myproc = gevent.spawn(self.myprocf, proc_finished_flag)
def myproc():
sleep(10)
proc_finished_flag.append('finished')
return 555
myproc = gevent.spawn(myproc)
link(myproc) link(myproc)
queue = Queue(0) queue = Queue(0)
...@@ -234,19 +230,31 @@ class LinksTestCase(greentest.TestCase): ...@@ -234,19 +230,31 @@ class LinksTestCase(greentest.TestCase):
assert with_timeout(DELAY, queue.get, timeout_value=X) is X, queue.get() assert with_timeout(DELAY, queue.get, timeout_value=X) is X, queue.get()
assert with_timeout(DELAY, gevent.joinall, [myproc], timeout_value=X) is X assert with_timeout(DELAY, gevent.joinall, [myproc], timeout_value=X) is X
assert proc_finished_flag == [], proc_finished_flag assert proc_finished_flag == [], proc_finished_flag
myproc.kill()
def return25():
return 25
def sleep0():
return sleep(0)
class TestReturn_link(LinksTestCase): class TestReturn_link(LinksTestCase):
link_method = 'link' link_method = 'link'
def cleanup(self):
self.p._links.clear()
def test_return(self): def test_return(self):
def return25(): self.p = gevent.spawn(return25)
return 25 self._test_return(self.p, True, 25, greenlet.LinkedCompleted, sleep0)
p = self.p = gevent.spawn(return25)
self._test_return(p, True, 25, greenlet.LinkedCompleted, lambda: sleep(0))
# repeating the same with dead process # repeating the same with dead process
for _ in xrange(3): for _ in xrange(3):
self._test_return(p, False, 25, greenlet.LinkedCompleted, lambda: sleep(0)) self._test_return(self.p, False, 25, greenlet.LinkedCompleted, sleep0)
self.p._links.clear()
self.p.kill()
def _test_return(self, p, first_time, result, kill_exc_type, action): def _test_return(self, p, first_time, result, kill_exc_type, action):
event, receiver, proc_flag, queue, callback_flag = self.set_links(p, first_time, kill_exc_type) event, receiver, proc_flag, queue, callback_flag = self.set_links(p, first_time, kill_exc_type)
...@@ -428,33 +436,39 @@ class TestStuff(greentest.TestCase): ...@@ -428,33 +436,39 @@ class TestStuff(greentest.TestCase):
sleep(DELAY * 10) sleep(DELAY * 10)
assert results in [[10, 20], [20, 10]], results assert results in [[10, 20], [20, 10]], results
def _test_multiple_listeners_error_unlink(self, p, link): class Results(object):
# notification must not happen after unlink even
# though notification process has been already started
results = []
def listener1(*args): def __init__(self):
p.unlink(listener2) self.results = []
results.append(5)
def listener1(self, p):
p.unlink(self.listener2)
self.results.append(5)
raise ExpectedError('listener1') raise ExpectedError('listener1')
def listener2(*args): def listener2(self, p):
p.unlink(listener1) p.unlink(self.listener1)
results.append(5) self.results.append(5)
raise ExpectedError('listener2') raise ExpectedError('listener2')
def listener3(*args): def listener3(self, p):
raise ExpectedError('listener3') raise ExpectedError('listener3')
link(listener1) def _test_multiple_listeners_error_unlink(self, p, link):
link(listener2) # notification must not happen after unlink even
link(listener3) # though notification process has been already started
results = self.Results()
link(results.listener1)
link(results.listener2)
link(results.listener3)
sleep(DELAY * 10) sleep(DELAY * 10)
assert results == [5], results assert results.results == [5], results.results
def test_multiple_listeners_error_unlink_Greenlet_link(self): def test_multiple_listeners_error_unlink_Greenlet_link(self):
p = gevent.spawn(lambda: 5) p = gevent.spawn(lambda: 5)
self._test_multiple_listeners_error_unlink(p, p.link) self._test_multiple_listeners_error_unlink(p, p.link)
p.kill()
def test_multiple_listeners_error_unlink_Greenlet_rawlink(self): def test_multiple_listeners_error_unlink_Greenlet_rawlink(self):
p = gevent.spawn(lambda: 5) p = gevent.spawn(lambda: 5)
...@@ -523,19 +537,31 @@ class TestStr(greentest.TestCase): ...@@ -523,19 +537,31 @@ class TestStr(greentest.TestCase):
class TestJoin(greentest.GenericWaitTestCase): class TestJoin(greentest.GenericWaitTestCase):
def wait(self, timeout): def wait(self, timeout):
gevent.spawn(gevent.sleep, 10).join(timeout=timeout) self.g = gevent.spawn(gevent.sleep, 10)
return self.g.join(timeout=timeout)
def cleanup(self):
self.g.kill()
class TestGet(greentest.GenericGetTestCase): class TestGet(greentest.GenericGetTestCase):
def wait(self, timeout): def wait(self, timeout):
gevent.spawn(gevent.sleep, 10).get(timeout=timeout) self.g = gevent.spawn(gevent.sleep, 10)
return self.g.get(timeout=timeout)
def cleanup(self):
self.g.kill()
class TestJoinAll(greentest.GenericWaitTestCase): class TestJoinAll(greentest.GenericWaitTestCase):
def wait(self, timeout): def wait(self, timeout):
gevent.joinall([gevent.spawn(gevent.sleep, 10)], timeout=timeout) self.g = gevent.spawn(gevent.sleep, 10)
gevent.joinall([self.g], timeout=timeout)
def cleanup(self):
self.g.kill()
class TestBasic(greentest.TestCase): class TestBasic(greentest.TestCase):
......
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