def test_successful_database_connection():
    result = test_database_connection(ReDB_HOST,
                                      ReDB_PORT,
                                      user=ReDB_USER,
                                      password=ReDB_PASS)
    assert result is not None
    assert result is True
Ejemplo n.º 2
0
def main():
    logging.basicConfig(format='%(asctime)s,%(msecs)-3d - %(name)-2s - '
                        '%(levelname)-2s => %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        level=logging.INFO)
    logging.info('[INFO] Starting RDM - Manager Service...')
    try:
        logging.info('[INFO] Testing RethinkDB Connection...')
        if not test_database_connection(ReDB_HOST, ReDB_PORT, ReDB_USER,
                                        ReDB_PASS):
            logging.critical('[CRITICAL] RDM couldn\'t connect with the'
                             ' database.\n Unable to start service!\n')
            raise Exception(f'No database connection!')
        loop = asyncio.get_event_loop()
        logging.info('[INFO] Starting WebSocket Server')
        loop.run_until_complete(server)
        logging.info('[INFO] WebSocket Server started')
        loop.run_forever()
    except KeyboardInterrupt:
        logging.exception(f'[EXCEPTION] System interrupted by user.')
        logging.info(f'[INFO] Trying to gracefully stop server...')
        loop.stop()
        loop.close()
        logging.info(f'[INFO] Server closed.')
    except Exception as err:
        logging.exception(f'[EXCEPTION] Error in system.\n{str(err)}')
        logging.info(f'[INFO] Trying to gracefully stop server...')
        loop.stop()
        loop.close()
    except ConnectionClosed as err:
        logging.exception(f'[EXCEPTION] Error in system.\n{str(err)}')
        logging.info(f'[INFO] Trying to gracefully stop server...')
        loop.stop()
        loop.close()
def test_unsuccessful_database_connection():
    result = test_database_connection(unknown_host, ReDB_PORT)
    assert result is not None
    assert result is False