async def test_depth( monkeypatch, input_file: str, expected_file: str, get_redis_client: Redis, ) -> None: await test_init(monkeypatch, get_redis_client) input_data = FileUtils.load_params_from_json(os.path.join(PATH, input_file)) expected_data = FileUtils.load_params_from_json(os.path.join(PATH, expected_file)) # monkeypatch.chdir(os.path.abspath(os.path.dirname(__file__))) if len(input_data) == len(expected_data): for i in range(len(input_data)): # logger.info(f"input line = {i}, and input_data[i]= {input_data[i]}") depth = get_results(input_data, i) # logger.info(f"depth : {depth}") for key, value in depth.items(): # logger.info(f"key, value - {key} and {value}") # below: get value for result key in expected results expected_result = expected_data[i][key] logger.info(f"expected_result : {expected_result}") assert value == expected_result await test_init(monkeypatch, get_redis_client) get_redis_client.close() await get_redis_client.wait_closed()
async def _print_stats(loop): worker_queue = config["WORKER_QUEUE"] pool = await create_connection_pool(loop) redis = Redis(pool) worker_queue_length = await redis.llen(worker_queue) requests = await get_counter(pool, "requests", 60) connects = await get_counter(pool, "connects", 60) errors = await get_counter(pool, "errors", 60) intercepted = await get_counter(pool, "intercepted", 60) not_authorized = await get_counter(pool, "not_authorized", 60) authorized = await get_counter(pool, "authorized", 60) ratelimited = await get_counter(pool, "ratelimited", 60) responses = await get_counter(pool, "responses", 60) session_count = ProxySession.query \ .count() request_count = Request.query \ .count() active_user_count = User.query \ .filter_by(active=True) \ .count() not_active_user_count = User.query \ .filter_by(active=False) \ .count() #intercept_count = Intercept.query \ # .count() print("proxy_sessions.value", session_count) print("requests.value", request_count) print("active_users.value", active_user_count) print("not_active_users.value", not_active_user_count) #print("user_intercepts.value", intercept_count) def calc_rate(l): rate = sum(map(int, l[1:6])) / 5 return '{0:.2f}'.format(rate) print("requests_5_minute.value " + calc_rate(requests)) print("connects_5_minute.value " + calc_rate(connects)) print("errors_5_minutes.value " + calc_rate(errors)) print("intercepted_5_minute.value " + calc_rate(intercepted)) print("not_authorized_5_minute.value " + calc_rate(not_authorized)) print("authorized_5_minute.value " + calc_rate(authorized)) print("ratelimited_5_minute.value " + calc_rate(ratelimited)) print("responses_5_minute.value " + calc_rate(responses)) print("worker_queue.value " + str(worker_queue_length)) redis.close() pool.close() await pool.wait_closed()
async def close_redis_connection(connection: aioredis.Redis) -> None: logger.info("Closing connection to Redis") # gracefully closing underlying connection connection.close() await connection.wait_closed() logger.info("Connection to Redis closed")
async def test_kline( monkeypatch, input_file: str, expected_file: str, get_redis_client: Redis, ) -> None: await test_init(monkeypatch, get_redis_client) input_data = FileUtils.load_params_from_json(os.path.join( PATH, input_file)) expected_data = FileUtils.load_params_from_json( os.path.join(PATH, expected_file)) if len(input_data) == len(expected_data): for i in range(len(input_data)): logger.info(f"input line = {i}") logger.info(input_data[i]) klines = get_results(input_data, i) # logger.info(f"klines : {klines}") for key, value in klines.items(): # logger.info(f"KLINE :: key: value is {key}:{value}") # below: get value for result key in expected results expected_result = expected_data[i][key] # logger.info(f"expected_result : {expected_result}") for key, value in value.items(): logger.info( f"individual kline, key: value is {key}:{value}") if key == "start_timestamp" or "end_timestamp": assert float(value) / float(expected_result[key]) == 1 else: assert value == expected_result[key] await test_init(monkeypatch, get_redis_client) get_redis_client.close() await get_redis_client.wait_closed()
async def close_connection(redis_client: aioredis.Redis): if redis_client is not None: redis_client.close() await redis_client.wait_closed()
async def close_connection(cache: aioredis.Redis) -> None: """Close the connection for a Redis cache object.""" cache.close() await cache.wait_closed()
async def _close(redis: Redis) -> None: if redis is not None: redis.close() await redis.wait_closed()
async def stop(redis_cli: Redis): redis_cli.close() await redis_cli.wait_closed()
async def close_redis(redis_cli: Redis): redis_cli.close() await redis_cli.wait_closed()
async def _print_stats(loop): worker_queue = config["WORKER_QUEUE"] pool = await create_connection_pool(loop) redis = Redis(pool) worker_queue_length = await redis.llen(worker_queue) requests_5s = await get_counter(pool, "requests", 5) requests_60s = await get_counter(pool, "requests", 60) requests_1h = await get_counter(pool, "requests", 3600) connects_5s = await get_counter(pool, "connects", 5) connects_60s = await get_counter(pool, "connects", 60) connects_1h = await get_counter(pool, "connects", 3600) errors_5s = await get_counter(pool, "errors", 5) errors_60s = await get_counter(pool, "errors", 60) errors_1h = await get_counter(pool, "errors", 3600) intercepted_5s = await get_counter(pool, "intercepted", 5) intercepted_60s = await get_counter(pool, "intercepted", 60) intercepted_1h = await get_counter(pool, "intercepted", 3600) not_authorized_5s = await get_counter(pool, "not_authorized", 5) not_authorized_60s = await get_counter(pool, "not_authorized", 60) not_authorized_1h = await get_counter(pool, "not_authorized", 3600) authorized_5s = await get_counter(pool, "authorized", 5) authorized_60s = await get_counter(pool, "authorized", 60) authorized_1h = await get_counter(pool, "authorized", 3600) ratelimited_5s = await get_counter(pool, "ratelimited", 5) ratelimited_60s = await get_counter(pool, "ratelimited", 60) ratelimited_1h = await get_counter(pool, "ratelimited", 3600) responses = await get_counter(pool, "responses", 5) print() print("Worker queue length : {}".format(worker_queue_length)) print() print("Requests 5s : {}".format(format_list(requests_5s))) print("Requests 60s : {}".format(format_list(requests_60s))) print("Requests 1h : {}".format(format_list(requests_1h))) print() print("HTTPS connects 5s : {}".format(format_list(connects_5s))) print("HTTPS connects 60s : {}".format(format_list(connects_60s))) print("HTTPS connects 1h : {}".format(format_list(connects_1h))) print() print("Responses : {}".format(format_list(responses))) print() print("HTTP errors 5s : {}".format(format_list(errors_5s))) print("HTTP errors 60s : {}".format(format_list(errors_60s))) print("HTTP errors 1h : {}".format(format_list(errors_1h))) print() print("ratelimited 5s : {}".format(format_list(ratelimited_5s))) print("ratelimited 60s : {}".format(format_list(ratelimited_60s))) print("ratelimited 1h : {}".format(format_list(ratelimited_1h))) print() print("authorized 5s : {}".format(format_list(authorized_5s))) print("authorized 60s : {}".format(format_list(authorized_60s))) print("authorized 1h : {}".format(format_list(authorized_1h))) print() print("not_authorized 5s : {}".format(format_list(not_authorized_5s))) print("not_authorized 60s : {}".format(format_list(not_authorized_60s))) print("not_authorized 1h : {}".format(format_list(not_authorized_1h))) print() print("intercepted 5s : {}".format(format_list(intercepted_5s))) print("intercepted 60s : {}".format(format_list(intercepted_60s))) print("intercepted 1h : {}".format(format_list(intercepted_1h))) #print(spark.spark_string(requests)) redis.close() pool.close() await pool.wait_closed()