def test_admin_disconnect_one(runner): '''Starts a server, then run a health check''' port = runner.port url = getDefaultHealthCheckUrl(None, port) role = getDefaultRoleForApp('health') secret = getDefaultSecretForApp('health') creds = createCredentials(role, secret) connection = Connection(url, creds) connectionToBeClosed = Connection(url, creds) asyncio.get_event_loop().run_until_complete( clientCoroutine(connection, connectionToBeClosed))
async def unsafeSubcribeClient( url, credentials, channel, position, fsqlFilter, messageHandlerClass, messageHandlerArgs, resumeFromLastPosition=False, resumeFromLastPositionId=None, batchSize=1, ): ''' No retry or exception handling Used by the health check, where we want to die hard and fast if there's a problem ''' connection = Connection(url, credentials) await connection.connect() message = await connection.subscribe( channel, position, fsqlFilter, messageHandlerClass, messageHandlerArgs, subscriptionId=channel, resumeFromLastPosition=resumeFromLastPosition, resumeFromLastPositionId=resumeFromLastPositionId, batchSize=batchSize, ) return message
async def client(url, creds, clientCallback, waitTime=None): '''Main client. Does authenticate then invoke the clientCallback which takes control. ''' # Wait N seconds by default before retrying to connect after an error if waitTime is None: waitTime = DEFAULT_CLIENT_WAIT_TIME while True: try: connection = Connection(url, creds) await connection.connect() return await clientCallback(connection) except TimeoutError as e: logging.error(e) await asyncio.sleep(waitTime) pass except ConnectionRefusedError as e: logging.error(e) await asyncio.sleep(waitTime) pass except ConnectionResetError as e: logging.error(e) await asyncio.sleep(waitTime) pass except websockets.exceptions.ConnectionClosedOK as e: logging.error(e) await asyncio.sleep(waitTime) pass except websockets.exceptions.ConnectionClosedError as e: logging.error(e) await asyncio.sleep(waitTime) pass except websockets.exceptions.InvalidMessage as e: logging.error(e) await asyncio.sleep(waitTime) pass except OSError as e: logging.error(e) await asyncio.sleep(waitTime) pass except EOFError as e: logging.error(e) await asyncio.sleep(waitTime) pass except HandshakeException as e: logging.error(e) await asyncio.sleep(waitTime) pass except AuthException as e: logging.error(e) await asyncio.sleep(waitTime) pass except ActionException as e: logging.error(e) await asyncio.sleep(waitTime) pass
def test_save_position(runner): '''Starts a server, then run a health check''' port = runner.port url = getDefaultHealthCheckUrl(None, port) role = getDefaultRoleForApp('health') secret = getDefaultSecretForApp('health') creds = createCredentials(role, secret) connection = Connection(url, creds) _ = Connection(url, creds) uniqueId = uuid.uuid4().hex[:8] channel = 'test_save_position_channel::' + uniqueId resumeFromLastPositionId = 'last_position_id::' + uniqueId asyncio.get_event_loop().run_until_complete( clientCoroutine(connection, channel, url, creds, resumeFromLastPositionId))
def test_publish(runner): port = runner.port url = getDefaultHealthCheckUrl(None, port) role = getDefaultRoleForApp('health') secret = getDefaultSecretForApp('health') creds = createCredentials(role, secret) connection = Connection(url, creds) asyncio.get_event_loop().run_until_complete(clientCoroutine(connection))
async def handler(url, credentials, channel, position): connection = Connection(url, credentials) await connection.connect() try: data = await connection.read(channel, position) except ActionException as e: logging.error(f'Action error: {e}') return await connection.close() print() print(f'handler received message {data}')
def test_monitor(runner): '''Starts a server, then run a health check''' port = runner.port url = getDefaultMonitorUrl(None, port) role = getDefaultRoleForApp('stats') secret = getDefaultSecretForApp('stats') creds = createCredentials(role, secret) connection = Connection(url, creds) asyncio.get_event_loop().run_until_complete(clientCoroutine(connection)) monitor(connection)
async def handler(url, credentials, channel, data, repeat): connection = Connection(url, credentials) await connection.connect() try: while True: await connection.write(channel, data) if not repeat: break except ActionException as e: logging.error(f'Action error: {e}') return await connection.close()
async def adminCoroutine(url, creds, action, connectionId): connection = Connection(url, creds) try: await connection.connect() except Exception as e: logging.error(f'Error connecting: {e}') return if action == 'get_connections': openedConnections = await connection.adminGetConnections() print(f'#{len(openedConnections)} connection(s)') for connection in openedConnections: print(f'\t{connection}') elif action == 'disconnect': await connection.adminCloseConnection(connectionId)
def test_monitor_redis_down(redisDownRunner): '''Starts a server, then run a health check''' port = redisDownRunner.port url = getDefaultMonitorUrl(None, port) role = getDefaultRoleForApp('stats') secret = getDefaultSecretForApp('stats') creds = createCredentials(role, secret) connection = Connection(url, creds) # FIXME: bring this back asyncio.get_event_loop().run_until_complete( clientCoroutineRedisDown(connection)) with pytest.raises(ActionException): monitor(connection)
async def kvHandler(url, credentials): connection = Connection(url, credentials) await connection.connect() key = uuid.uuid4().hex val = uuid.uuid4().hex await connection.write(key, val) data = await connection.read(key) if val != data: raise ValueError('read/write test failed') await connection.delete(key) data = await connection.read(key) if data is not None: raise ValueError('delete/read test failed') await connection.close()