def test_local(local_broadcaster): cb_calls = [0, 0] def cb1(data): cb_calls[0] += 1 return data + 1 def cb2(): cb_calls[1] += 1 assert broadcast.broadcast("test1", {'data': 1}, expect_answers=True) == [] assert cb_calls == [0, 0] broadcast.subscribe("test1", cb1) broadcast.subscribe("test2", cb2) assert cb_calls == [0, 0] assert broadcast.broadcast("test1", {'data': 1}) is None assert cb_calls == [1, 0] assert broadcast.broadcast("test2") is None assert cb_calls == [1, 1] assert broadcast.broadcast("test1", {'data': 12}, expect_answers=True) == [13] assert cb_calls == [2, 1] broadcast.unsubscribe("test1") assert broadcast.broadcast("test1", {'data': 1}, expect_answers=True) == [] assert cb_calls == [2, 1]
def _sql_profiler_view(request: pyramid.request.Request) -> Mapping[str, Any]: auth.auth_view(request) enable = request.params.get("enable") if enable is not None: broadcast.broadcast("c2c_sql_profiler", params={"enable": enable}, expect_answers=True) return {"status": 200, "enabled": repository is not None}
def _sql_profiler_view(request: pyramid.request.Request) -> Mapping[str, Any]: global repository auth.auth_view(request) enable = request.params.get('enable') if enable is not None: broadcast.broadcast('c2c_sql_profiler', params={'enable': enable}, expect_answers=True) return {'status': 200, 'enabled': repository is not None}
def refresh(id_, key): """ This is called from the web service to start a refresh. """ LOG.info("Reloading the %s config", id_) source, _ = check_id_key(id_, key) if source is None: raise HTTPNotFound(f"Unknown id {id_}") source.refresh() if source.is_master() and ( not MASTER_SOURCE or not MASTER_SOURCE.get_config().get("standalone", False)): reload_master_config() broadcast.broadcast("slave_fetch", params=dict(id_=id_, key=key))
def test_fallback(): cb_calls = [0] def cb1(value): cb_calls[0] += 1 return value + 1 try: broadcast.subscribe("test1", cb1) assert broadcast.broadcast("test1", {'value': 12}, expect_answers=True) == [13] assert cb_calls == [1] finally: broadcast._broadcaster = None # pylint: disable=W0212
def _dump_memory(request: pyramid.request.Request) -> List[Mapping[str, Any]]: auth.auth_view(request) limit = int(request.params.get("limit", "30")) analyze_type = request.params.get("analyze_type") python_internals_map = request.params.get("python_internals_map", "0").lower() in ("", "1", "true", "on") result = broadcast.broadcast( "c2c_dump_memory", params={ "limit": limit, "analyze_type": analyze_type, "python_internals_map": python_internals_map }, expect_answers=True, timeout=70, ) assert result is not None return result
def _dump_stacks(request: pyramid.request.Request) -> List[Mapping[str, Any]]: auth.auth_view(request) result = broadcast.broadcast("c2c_dump_stacks", expect_answers=True) assert result is not None return _beautify_stacks(result)