Esempio n. 1
0
def test_http_unassignment(db, default_account):
    purge_other_accounts(default_account)
    s = patched_sync_service(db)
    default_account.desired_sync_host = None
    default_account.sync_host = None
    db.session.commit()
    s.poll_shared_queue({"queue_name": "foo", "id": default_account.id})

    frontend = SyncHTTPFrontend(s, 16384, False, False)
    app = frontend._create_app()
    app.config["TESTING"] = True
    with app.test_client() as c:
        resp = c.post(
            "/unassign",
            data=json.dumps({"account_id": default_account.id}),
            content_type="application/json",
        )
        assert resp.status_code == 200
    db.session.expire_all()
    assert default_account.sync_host is None

    # Check that 409 is returned if account is not actually assigned to
    # process.
    with app.test_client() as c:
        resp = c.post(
            "/unassign",
            data=json.dumps({"account_id": default_account.id}),
            content_type="application/json",
        )
        assert resp.status_code == 409
Esempio n. 2
0
def test_http_unassignment(db, default_account):
    purge_other_accounts(default_account)
    s = patched_sync_service(db)
    default_account.desired_sync_host = None
    default_account.sync_host = None
    db.session.commit()
    s.poll_shared_queue({'queue_name': 'foo', 'id': default_account.id})

    frontend = SyncHTTPFrontend(s, 16384, False, False)
    app = frontend._create_app()
    app.config['TESTING'] = True
    with app.test_client() as c:
        resp = c.post(
            '/unassign', data=json.dumps({'account_id': default_account.id}),
            content_type='application/json')
        assert resp.status_code == 200
    db.session.expire_all()
    assert default_account.sync_host is None

    # Check that 409 is returned if account is not actually assigned to
    # process.
    with app.test_client() as c:
        resp = c.post(
            '/unassign', data=json.dumps({'account_id': default_account.id}),
            content_type='application/json')
        assert resp.status_code == 409
Esempio n. 3
0
def test_http_frontend(db, default_account, monkeypatch):
    s = patched_sync_service(db)
    s.poll({"queue_name": "foo"})

    monkeypatch.setattr("pympler.muppy.get_objects", lambda *args: [])
    monkeypatch.setattr("pympler.summary.summarize", lambda *args: [])

    frontend = SyncHTTPFrontend(s, 16384, trace_greenlets=True, profile=True)
    app = frontend._create_app()
    app.config["TESTING"] = True
    with app.test_client() as c:
        resp = c.get("/profile")
        assert resp.status_code == 200
        resp = c.get("/load")
        assert resp.status_code == 200
        resp = c.get("/mem")
        assert resp.status_code == 200
    monkeypatch.undo()
Esempio n. 4
0
def test_http_frontend(db, default_account, monkeypatch):
    s = patched_sync_service(db)
    s.poll({'queue_name': 'foo'})

    monkeypatch.setattr('pympler.muppy.get_objects', lambda *args: [])
    monkeypatch.setattr('pympler.summary.summarize', lambda *args: [])

    frontend = SyncHTTPFrontend(s, 16384, trace_greenlets=True, profile=True)
    app = frontend._create_app()
    app.config['TESTING'] = True
    with app.test_client() as c:
        resp = c.get('/profile')
        assert resp.status_code == 200
        resp = c.get('/load')
        assert resp.status_code == 200
        resp = c.get('/mem')
        assert resp.status_code == 200
    monkeypatch.undo()
Esempio n. 5
0
def main(prod, enable_tracer, enable_profiler, config, process_num,
         exit_after):
    """ Launch the Nylas sync service. """
    level = os.environ.get("LOGLEVEL", inbox_config.get("LOGLEVEL"))
    configure_logging(log_level=level)
    reconfigure_logging()

    maybe_enable_rollbar()

    if config is not None:
        from inbox.util.startup import load_overrides

        config_path = os.path.abspath(config)
        load_overrides(config_path)

    if not prod:
        preflight()

    total_processes = int(os.environ.get("MAILSYNC_PROCESSES", 1))

    setproctitle.setproctitle("sync-engine-{}".format(process_num))

    log = get_logger()
    log.info(
        "start",
        components=["mail sync", "contact sync", "calendar sync"],
        host=platform.node(),
        process_num=process_num,
        total_processes=total_processes,
        recursion_limit=sys.getrecursionlimit(),
    )

    print(banner, file=sys.stderr)
    print(file=sys.stderr)
    print("Python", sys.version, file=sys.stderr)

    if enable_profiler:
        inbox_config["DEBUG_PROFILING_ON"] = True

    port = 16384 + process_num
    enable_profiler_api = inbox_config.get("DEBUG_PROFILING_ON")

    process_identifier = "{}:{}".format(platform.node(), process_num)

    if exit_after:
        exit_after = exit_after.split(":")
        exit_after_min, exit_after_max = int(exit_after[0]), int(exit_after[1])
    else:
        exit_after_min, exit_after_max = None, None

    sync_service = SyncService(
        process_identifier,
        process_num,
        exit_after_min=exit_after_min,
        exit_after_max=exit_after_max,
    )
    signal.signal(signal.SIGTERM, sync_service.stop)
    signal.signal(signal.SIGINT, sync_service.stop)
    http_frontend = SyncHTTPFrontend(sync_service, port, enable_tracer,
                                     enable_profiler_api)
    sync_service.register_pending_avgs_provider(http_frontend)
    http_frontend.start()

    sync_service.run()

    print("\033[94mNylas Sync Engine exiting...\033[0m", file=sys.stderr)