def test_error_state(self): from stpclient import Client from stpclient.exceptions import STPNetworkError client = Client('localhost', 0, timeout=1) assert not client.closed try: client.call('ping') except STPNetworkError: pass assert client.closed
def test_timeout_state(self): from stpclient import Client from stpclient.exceptions import STPTimeoutError import time client = Client('localhost', 9999, timeout=1) assert not client.closed try: client.call('long') except STPTimeoutError: time.sleep(2) assert client.closed client.call('ping')
def main(): host = sys.argv[1] port = int(sys.argv[2]) if len(sys.argv) > 3: count = int(sys.argv[3]) else: count = 1 client = Client(host, port, timeout=1) for i in range(count): try: print client.call('ping').argv except: logging.exception('') client.close() time.sleep(0.5)
class MagicClient(local): def __init__(self, *args, **kwargs): self.client = Client(*args, **kwargs) def __getattr__(self, name): def stpcall(*args): resp = self.client.call((name,) + args).argv if resp[0] == 'ERR': raise Exception(resp[1]) else: return resp[1:] return stpcall
def test_sync(): client = Client('localhost', 9999, timeout=1) try: print client.call('long') except Exception as e: print e time.sleep(1) print client.call('ping').argv print 'sleep 10s' time.sleep(10) print 'ping again' try: print client.call('ping').argv except Exception as e: print e time.sleep(10) print 'ping again' print client.call('ping').argv
def __init__(self, *args, **kwargs): self.client = Client(*args, **kwargs)
def test_not_timeout(self): from stpclient import Client client = Client('localhost', 9999, timeout=1) assert not client.closed client.call('ping')
def test_connect(self): from stpclient import Client client = Client('localhost', 9999, timeout=1) assert not client.closed client.close() assert client.closed
def test_ping(self): from stpclient import Client client = Client('localhost', 9999, timeout=1) resp = client.call('ping') eq_(resp[0], 'OK') eq_(resp[1], 'PONG')