def main(): with get_socket() as sock: client = SynClient(sock) for _ in range(10000): begin = time.perf_counter() client.request('time', 'date') end = time.perf_counter() print((end - begin) * 1000)
def test_logger(): # Start our test service p = multiprocessing.Process(target=main) p.start() time.sleep(.2) # Give it time to start c = SynClient() c.subscribe('log.logger*') cs = CellaservProxy() cs.logger.do_log() # Send request time.sleep(.2) # Give it time to crash # Ensure that we have our 4 log messages for _ in range(4): assert c.read_message().type == Message.Publish p.terminate()
def test_basic(): c = SynClient() c.subscribe('log.coding-error') # Setup our client to timeout when there no message is recv c._socket.settimeout(.1) # Send good publish c.publish(event='foo', data=json.dumps({'a': '0'}).encode()) assert not recv(c) # Internal error c.publish(event='foo', data=json.dumps({'a': 'hello'}).encode()) assert recv(c) # Bad publish args c.publish(event='foo', data=json.dumps({'b': '0'}).encode()) assert recv(c)
def run_client(n): with get_socket() as sock: client = SynClient(sock) for _ in range(n): client.request('time', 'date')