This commit is contained in:
Denis Bilenko
2009-05-19 20:27:04 +07:00
parent 75b6315b62
commit 78bc7e0e72

View File

@@ -22,7 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from eventlet import saranwrap, coros
from eventlet import api, saranwrap, coros
import os
import sys
@@ -39,6 +39,20 @@ one = 1
two = 2
three = 3
class CoroutineCallingClass(object):
def __init__(self):
self._my_dict = {}
def run_coroutine(self):
api.spawn(self._add_random_key)
def _add_random_key(self):
self._my_dict['random'] = 'yes, random'
def get_dict(self):
return self._my_dict
class TestSaranwrap(unittest.TestCase):
def assert_server_exists(self, prox):
self.assert_(saranwrap.status(prox))
@@ -209,6 +223,11 @@ class TestSaranwrap(unittest.TestCase):
#print status_after['objects']
self.assertLessThan(status_after['object_count'], status_before['object_count'])
def test_contains(self):
prox = saranwrap.wrap({'a':'b'})
self.assert_('a' in prox)
self.assert_('x' not in prox)
def test_variable_and_keyword_arguments_with_function_calls(self):
import optparse
prox = saranwrap.wrap(optparse)
@@ -300,6 +319,24 @@ sys_path = sys.path""")
prox = saranwrap.wrap([saranwrap_test.list_maker])
self.assertEquals(list_maker(), prox[0]())
def test_under_the_hood_coroutines(self):
# so, we want to write a class which uses a coroutine to call
# a function. Then we want to saranwrap that class, have
# the object call the coroutine and verify that it ran
from greentest import saranwrap_test
mod_proxy = saranwrap.wrap(saranwrap_test)
obj_proxy = mod_proxy.CoroutineCallingClass()
obj_proxy.run_coroutine()
# sleep for a bit to make sure out coroutine ran by the time
# we check the assert below
api.sleep(0.1)
self.assert_(
'random' in obj_proxy.get_dict(),
'Coroutine in saranwrapped object did not run')
def test_detection_of_server_crash(self):
# make the server crash here
pass