def test_healthchecks_bad_connection(entrypoint, click_app, mocker): mocker.patch.object( click_app.job_manager, "check_connection", side_effect=exceptions.ConnectorException("Something's wrong"), ) result = entrypoint("-a yay healthchecks") assert result.output.strip() == "Error: Something's wrong"
def wrapped(*args, **kwargs): final_exc = None try: max_tries = args[0]._pool.maxconn + 1 except Exception: max_tries = 1 for _ in range(max_tries): try: return func(*args, **kwargs) except psycopg2.errors.AdminShutdown: continue raise exceptions.ConnectorException( "Could not get a valid connection after {} tries".format( max_tries)) from final_exc
async def wrapped(*args, **kwargs): final_exc = None try: max_tries = args[0]._pool.maxsize + 1 except Exception: max_tries = 1 for _ in range(max_tries): try: return await coro(*args, **kwargs) except psycopg2.errors.OperationalError as exc: if "server closed the connection unexpectedly" in str(exc): final_exc = exc continue raise exc raise exceptions.ConnectorException( f"Could not get a valid connection after {max_tries} tries" ) from final_exc