<s> from nose . tools import assert_raises <EOL> import gevent <EOL> import sys <EOL> from zerorpc import zmq <EOL> import zerorpc <EOL> from testutils import teardown , random_ipc_endpoint , TIME_FACTOR <EOL> def test_client_server_client_timeout_with_async ( ) : <EOL> endpoint = random_ipc_endpoint ( ) <EOL> class MySrv ( zerorpc . Server ) : <EOL> def lolita ( self ) : <EOL> return <NUM_LIT> <EOL> def add ( self , a , b ) : <EOL> gevent . sleep ( TIME_FACTOR * <NUM_LIT:10> ) <EOL> return a + b <EOL> srv = MySrv ( ) <EOL> srv . bind ( endpoint ) <EOL> gevent . spawn ( srv . run ) <EOL> client = zerorpc . Client ( timeout = TIME_FACTOR * <NUM_LIT:2> ) <EOL> client . connect ( endpoint ) <EOL> async_result = client . add ( <NUM_LIT:1> , <NUM_LIT:4> , async = True ) <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> def _do_with_assert_raises ( ) : <EOL> print async_result . get ( ) <EOL> assert_raises ( zerorpc . TimeoutExpired , _do_with_assert_raises ) <EOL> else : <EOL> with assert_raises ( zerorpc . TimeoutExpired ) : <EOL> print async_result . get ( ) <EOL> client . close ( ) <EOL> srv . close ( ) <EOL> def test_client_server_with_async ( ) : <EOL> endpoint = random_ipc_endpoint ( ) <EOL> class MySrv ( zerorpc . Server ) : <EOL> def lolita ( self ) : <EOL> return <NUM_LIT> <EOL> def add ( self , a , b ) : <EOL> return a + b <EOL> srv = MySrv ( ) <EOL> srv . bind ( endpoint ) <EOL> gevent . spawn ( srv . run ) <EOL> client = zerorpc . Client ( ) <EOL> client . connect ( endpoint ) <EOL> async_result = client . lolita ( async = True ) <EOL> assert async_result . get ( ) == <NUM_LIT> <EOL> async_result = client . add ( <NUM_LIT:1> , <NUM_LIT:4> , async = True ) <EOL> assert async_result . get ( ) == <NUM_LIT:5> </s>
