Esempio n. 1
0
def setUpModule():
    """Sets up the environment for testing."""
    global server_thread

    server_port = get_free_port()

    FLAGS.fetch_frequency = 100
    FLAGS.fetch_threads = 1
    FLAGS.phantomjs_timeout = 60
    FLAGS.polltime = 1
    FLAGS.queue_idle_poll_seconds = 1
    FLAGS.queue_busy_poll_seconds = 1
    FLAGS.queue_server_prefix = (
        'http://localhost:%d/api/work_queue' % server_port)
    FLAGS.release_server_prefix = 'http://localhost:%d/api' % server_port

    db_path = tempfile.mktemp(suffix='.db')
    logging.info('sqlite path used in tests: %s', db_path)
    server.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_path
    db.drop_all()
    db.create_all()

    server.app.config['CSRF_ENABLED'] = False
    server.app.config['IGNORE_AUTH'] = True
    server.app.config['TESTING'] = True
    run = lambda: server.app.run(debug=False, host='0.0.0.0', port=server_port)

    server_thread = threading.Thread(target=run)
    server_thread.setDaemon(True)
    server_thread.start()

    runworker.run_workers()
Esempio n. 2
0
def setUpModule():
    """Sets up the environment for testing."""
    global server_thread

    server_port = get_free_port()

    FLAGS.fetch_frequency = 100
    FLAGS.fetch_threads = 1
    FLAGS.phantomjs_timeout = 60
    FLAGS.polltime = 1
    FLAGS.queue_idle_poll_seconds = 1
    FLAGS.queue_busy_poll_seconds = 1
    FLAGS.queue_server_prefix = ('http://localhost:%d/api/work_queue' %
                                 server_port)
    FLAGS.release_server_prefix = 'http://localhost:%d/api' % server_port

    db_path = tempfile.mktemp(suffix='.db')
    logging.info('sqlite path used in tests: %s', db_path)
    server.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_path
    db.drop_all()
    db.create_all()

    server.app.config['CSRF_ENABLED'] = False
    server.app.config['IGNORE_AUTH'] = True
    server.app.config['TESTING'] = True
    run = lambda: server.app.run(debug=False, host='0.0.0.0', port=server_port)

    server_thread = threading.Thread(target=run)
    server_thread.setDaemon(True)
    server_thread.start()

    runworker.run_workers()
Esempio n. 3
0
def setUpModule():
    """Sets up the environment for testing."""
    global server_thread

    server_port = get_free_port()

    FLAGS.fetch_frequency = 100
    FLAGS.fetch_threads = 1
    FLAGS.phantomjs_timeout = 60
    FLAGS.polltime = 1
    FLAGS.queue_poll_seconds = 1
    FLAGS.queue_server_prefix = (
        'http://localhost:%d/api/work_queue' % server_port)
    FLAGS.release_server_prefix = 'http://localhost:%d/api' % server_port

    db.drop_all()
    db.create_all()


    server.app.config['CSRF_ENABLED'] = False
    server.app.config['IGNORE_AUTH'] = True
    server.app.config['TESTING'] = True
    run = lambda: server.app.run(debug=False, host='0.0.0.0', port=server_port)

    server_thread = threading.Thread(target=run)
    server_thread.setDaemon(True)
    server_thread.start()

    runworker.run_workers()
Esempio n. 4
0
    except gflags.FlagsError, e:
        print '%s\nUsage: %s ARGS\n%s' % (e, sys.argv[0], FLAGS)
        sys.exit(1)

    logging.basicConfig(
        format='%(levelname)s %(filename)s:%(lineno)s] %(message)s')
    if FLAGS.verbose:
        logging.getLogger().setLevel(logging.DEBUG)
    else:
        logging.getLogger().setLevel(logging.INFO)

    if FLAGS.verbose_queries:
        logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)

    if FLAGS.local_queue_workers:
        coordinator = runworker.run_workers()
        # If the babysitter thread dies, the whole process goes down.
        def worker_babysitter():
            try:
                coordinator.wait_one()
            finally:
                os._exit(1)

        babysitter_thread = threading.Thread(target=worker_babysitter)
        babysitter_thread.setDaemon(True)
        babysitter_thread.start()

    if FLAGS.ignore_auth:
        server.app.config['IGNORE_AUTH'] = True

    server.app.run(debug=FLAGS.reload_code, port=FLAGS.port)
Esempio n. 5
0
    except gflags.FlagsError, e:
        print '%s\nUsage: %s ARGS\n%s' % (e, sys.argv[0], FLAGS)
        sys.exit(1)

    logging.basicConfig(
        format='%(levelname)s %(filename)s:%(lineno)s] %(message)s')
    if FLAGS.verbose:
        logging.getLogger().setLevel(logging.DEBUG)
    else:
        logging.getLogger().setLevel(logging.INFO)

    if FLAGS.verbose_queries:
        logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)

    if FLAGS.local_queue_workers:
        coordinator = runworker.run_workers()

        # If the babysitter thread dies, the whole process goes down.
        def worker_babysitter():
            try:
                coordinator.wait_one()
            finally:
                os._exit(1)

        babysitter_thread = threading.Thread(target=worker_babysitter)
        babysitter_thread.setDaemon(True)
        babysitter_thread.start()

    if FLAGS.ignore_auth:
        server.app.config['IGNORE_AUTH'] = True