diff --git a/eco/acquisition/daq_client.py b/eco/acquisition/daq_client.py index bac8d47..0ab1f53 100644 --- a/eco/acquisition/daq_client.py +++ b/eco/acquisition/daq_client.py @@ -2162,6 +2162,8 @@ class Daq(Assembly): ) except Exception as exc: return self._status_server_failed("start monitoring", exc) + from eco.status_server.client import warn_recording_failed_required + scan.counter_scratch(self.name)["monitoring_recording_id"] = recording_id print( f"monitoring: recording '{recording_id}' started on " @@ -2169,6 +2171,7 @@ class Daq(Assembly): f"({result.get('n_channels_attached')}/" f"{result.get('n_channels_requested')} channels attached)" ) + warn_recording_failed_required(result) return result def end_scan_monitoring(self, scan, pgroup=None, upload=True, **kwargs): diff --git a/eco/status_server/client.py b/eco/status_server/client.py index dcc1cdd..f900d69 100644 --- a/eco/status_server/client.py +++ b/eco/status_server/client.py @@ -86,6 +86,37 @@ def warn_failed_required(health): return failed +def warn_recording_failed_required(result): + """Shout, in red, about required-component channels a recording could + not attach to. + + Same "everyone else failing is expected, this failing is not" + distinction as warn_failed_required, but for a running recording's own + attach failures - not to be confused with that one: a channel can fail + to attach here (demoted, disconnected, no underlying PV) even though + its component initialized perfectly fine, so this deliberately does not + suggest client.reinit() the way warn_failed_required does - rebuilding + the namespace would not fix a channel that simply never connects. + + Returns the list it warned about (empty if there was nothing to say). + """ + failed = list((result or {}).get("failed_required") or []) + if not failed: + return [] + red, reset = colorama.Fore.RED + colorama.Style.BRIGHT, colorama.Style.RESET_ALL + print( + f"{red}!!! monitoring: {len(failed)} REQUIRED component channel(s) " + f"could not be attached: {', '.join(failed)}{reset}", + flush=True, + ) + print( + f"{red} This run's namespace_monitor.h5 will be missing them - see " + f"client.recording(recording_id).{reset}", + flush=True, + ) + return failed + + class StatusServerError(RuntimeError): pass @@ -415,8 +446,23 @@ class StatusServerClient: } return self._post("/recording/start", body, ok_codes=(200, 202)) - def recording(self, recording_id, channels=False) -> dict: - suffix = "?channels=1" if channels else "" + def recording(self, recording_id, channels=False, size=False, + size_top_n=None) -> dict: + """size=True adds "size_per_channel": a projected-bandwidth + estimate per channel (rate * value size - "frequency * data shape + * bitdepth"), sorted biggest first, from this recording's own + buffers so far - works on a still-running recording, meant for + judging storage/bandwidth cost from a short trial before + committing to a long one. size_top_n caps how many channels come + back (the point is usually "what are the biggest contributors").""" + params = [] + if channels: + params.append("channels=1") + if size: + params.append("size=1") + if size_top_n: + params.append(f"size_top_n={int(size_top_n)}") + suffix = "?" + "&".join(params) if params else "" return self._get(f"/recording/{recording_id}{suffix}") def recordings(self) -> list: diff --git a/eco/status_server/namespace_component.py b/eco/status_server/namespace_component.py index 2c8a7fb..d7eb043 100644 --- a/eco/status_server/namespace_component.py +++ b/eco/status_server/namespace_component.py @@ -9,54 +9,81 @@ Daq turns into its own ``StatusServerClient`` internally, see poked at directly from a session - ``bernina.status_server.gui()``, ``.status()``, ``.restart()`` - and to hold the settings a human actually wants to see and change (recording mode, throttle interval, max element -size, ...) as real ``AdjustableMemory`` children, the way any other -device's configuration shows up in ``.settings()``, instead of as -hardcoded literals buried in ``bernina_daq.py`` or ``Daq``'s own kwargs. +size, ...) as real ``AdjustableFS`` children, the way any other device's +filesystem-backed configuration shows up in ``.settings()``, instead of +as hardcoded literals buried in ``bernina_daq.py`` or ``Daq``'s own +kwargs. -Currently a read/inspect surface for the settings - nothing in ``Daq`` -consults these yet (``start_scan_monitoring`` still uses its own -mode="throttle"/min_interval=0.1 defaults). Wiring them through so -changing a setting here actually changes what the next scan does is a -natural next step, not yet done. +AdjustableFS, not AdjustableMemory, deliberately: a setting changed in one +session must be visible to *any other process* that can read the same +shared filesystem - another session, or the status server process itself +- with no REST call or other new communication of its own, the same way +``channels_JF``/``config_JFs`` already work in ``bernina_daq.py``. Each +setting is its own small JSON file under ``config_dir`` (default: the +shared ``eco_cnf_bernina/configuration`` tree), read with AdjustableFS's +own short TTL cache (``ADJUSTABLEFS_MAX_READ_PERIOD``, 0.2 s) rather than +once at import time. + +Currently a read/inspect surface for the settings - nothing (not Daq, not +the server) consults these yet (``start_scan_monitoring`` still uses its +own mode="throttle"/min_interval=0.1 defaults). Being filesystem-based is +what would let the server read them directly, without inventing a new +settings-push endpoint - actually doing that is a natural next step, not +yet done. """ from __future__ import annotations import subprocess import sys +from pathlib import Path -from eco.elements.adjustable import AdjustableMemory +from eco.elements.adjustable import AdjustableFS from eco.elements.assembly import Assembly from .client import StatusServerClient, warn_failed_required +# The same shared tree bernina_daq.py's channels_JF/config_JFs/etc already +# use - see eco.utilities.datafiles for why this needs to be a group- +# writable tree (AdjustableFS handles that itself, same as those). +_DEFAULT_CONFIG_DIR = "/sf/bernina/code/gac-bernina/eco_cnf_bernina/configuration" + class StatusServer(Assembly): - def __init__(self, base_url: str, name=None): + def __init__(self, base_url: str, name=None, config_dir=None): super().__init__(name=name) self.base_url = base_url self._client = StatusServerClient(base_url) self._gui_proc = None - # -- settings: what a server-backed scan should do. Real - # AdjustableMemory children so they show up in .settings()/status() - # like any other device's configuration - not yet read by Daq, see - # the module docstring. - self._append(AdjustableMemory, "throttle", name="recording_mode", - is_setting=True) - self._append(AdjustableMemory, 0.1, name="recording_min_interval", - is_setting=True) - self._append(AdjustableMemory, 0.1, name="recording_sample_interval", - is_setting=True) + cfg = Path(config_dir) if config_dir is not None else Path(_DEFAULT_CONFIG_DIR) + self._append( + AdjustableFS, str(cfg / "status_server_recording_mode.json"), + default_value="throttle", name="recording_mode", is_setting=True, + ) + self._append( + AdjustableFS, str(cfg / "status_server_recording_min_interval.json"), + default_value=0.1, name="recording_min_interval", is_setting=True, + ) + self._append( + AdjustableFS, str(cfg / "status_server_recording_sample_interval.json"), + default_value=0.1, name="recording_sample_interval", is_setting=True, + ) # "maximum_element_size": the largest value (by element count) a # recording will store - None keeps everything, including # waveforms. See RecordingSession/write_monitor_recording's own # docs for why this is usually the one knob that matters most for # file size. - self._append(AdjustableMemory, None, name="recording_max_value_elements", - is_setting=True) - self._append(AdjustableMemory, 100_000, - name="recording_max_points_per_channel", is_setting=True) + self._append( + AdjustableFS, str(cfg / "status_server_recording_max_value_elements.json"), + default_value=None, name="recording_max_value_elements", is_setting=True, + ) + self._append( + AdjustableFS, + str(cfg / "status_server_recording_max_points_per_channel.json"), + default_value=100_000, name="recording_max_points_per_channel", + is_setting=True, + ) # -- control -------------------------------------------------------- diff --git a/eco/status_server/namespace_server.py b/eco/status_server/namespace_server.py index 3d4213c..f4a4a77 100644 --- a/eco/status_server/namespace_server.py +++ b/eco/status_server/namespace_server.py @@ -664,11 +664,14 @@ def create_namespace_app( @app.get("/recording/") def recording_get(recording_id): + size_top_n = request.args.get("size_top_n", type=int) try: return jsonify( store.recording_report( recording_id, with_channels=request.args.get("channels") in ("1", "true", "yes"), + with_size=request.args.get("size") in ("1", "true", "yes"), + size_top_n=size_top_n, ) ) except KeyError as exc: diff --git a/eco/status_server/namespace_store.py b/eco/status_server/namespace_store.py index ba6b920..969958b 100644 --- a/eco/status_server/namespace_store.py +++ b/eco/status_server/namespace_store.py @@ -62,6 +62,8 @@ import threading import time from concurrent.futures import ThreadPoolExecutor +import numpy as np + from eco.elements.adjustable import CallbackComposedValue from eco.elements.protocols import Detector, MonitorableValueUpdate @@ -680,6 +682,12 @@ class NamespaceMonitorStore: detectors = [ (name, obj, self._channels.get(name)) for name, obj in selected ] + try: + required_component_names = set(self.namespace.required_names()) + except Exception: + logger.debug("could not read required_names() for recording %s", + recording_id, exc_info=True) + required_component_names = set() session = RecordingSession( recording_id, detectors, @@ -691,6 +699,7 @@ class NamespaceMonitorStore: subscription_mask=subscription_mask, pgroup=pgroup, run_number=run_number, + required_component_names=required_component_names, ) session.start() self._recordings[recording_id] = session @@ -744,11 +753,15 @@ class NamespaceMonitorStore: "data": data, } - def recording_report(self, recording_id, with_channels=False): + def recording_report(self, recording_id, with_channels=False, with_size=False, + size_top_n=None): session = self._recordings.get(recording_id) if session is None: raise KeyError(f"no such recording '{recording_id}'") - return session.report(with_channels=with_channels) + rep = session.report(with_channels=with_channels) + if with_size: + rep["size_per_channel"] = session.size_report(top_n=size_top_n) + return rep def list_recordings(self): with self._recordings_lock: @@ -988,6 +1001,7 @@ class RecordingSession: subscription_mask=True, pgroup=None, run_number=None, + required_component_names=None, ): if mode not in ("all", "throttle", "sample"): raise ValueError(f"unknown recording mode {mode!r}") @@ -999,6 +1013,14 @@ class RecordingSession: # otherwise. self.pgroup = pgroup self.run_number = run_number + # Top-level namespace component names (namespace.required_names()) + # - a channel whose full_name starts with one of these and failed to + # attach is reported separately in report()'s failed_required, the + # same distinction /health's failed_required already makes for init + # failures. A full_name's top-level component is everything before + # its first ".", matching Alias.get_full_name(base=None)'s own + # dotted convention. + self._required_names = set(required_component_names or ()) self.mode = mode self.min_interval = float(min_interval) self.sample_interval = float(sample_interval) @@ -1040,6 +1062,10 @@ class RecordingSession: self.n_attached = 0 self.n_seeded = 0 self.n_backfilled = 0 + # Names (not just a count) of channels that failed to attach - kept + # so NamespaceMonitorStore.start_recording can classify them against + # namespace.required_names(), same as /health's failed_required. + self._attach_failed_names = [] # -- lifecycle --------------------------------------------------------- @@ -1051,6 +1077,7 @@ class RecordingSession: mon = obj.set_current_value_callback(func=self._make_callback(name)) if mon is None: self.n_attach_failed += 1 + self._attach_failed_names.append(name) continue # with_ctrlvars=False always: get_ctrlvars() (units, limits, # precision) is a blocking CA round trip per channel @@ -1102,6 +1129,7 @@ class RecordingSession: self.n_seeded += 1 except Exception: self.n_attach_failed += 1 + self._attach_failed_names.append(name) logger.debug("could not attach a recording monitor to %s", name, exc_info=True) if self.mode == "sample": @@ -1282,12 +1310,76 @@ class RecordingSession: self.n_backfilled += filled return filled + def size_report(self, top_n=None): + """Per-channel projected size: rate (this channel's own point + count over the recording's elapsed time so far) times a sample + value's size (element count * dtype itemsize, i.e. "frequency * + data shape * bitdepth") - to judge storage/bandwidth cost from a + short trial recording before committing to a long one, without + needing to guess or wait for the real thing to finish. + + Works on a still-running recording (reads the live buffers - the + same lax race tolerance as the rest of this class: a value read + here while a CA callback is mid-append is not locked against + beyond the dict-level snapshot, see stop()'s own docstring) as + well as a stopped one, though a stopped session's buffers are + empty (stop() hands them to the caller) - call this before + stop(), not after, if you want it there too. + + Returns ``{full_name: {"n_points", "rate_hz", "n_elements", + "bytes_per_point", "projected_bytes_per_s"}}``, sorted by + projected_bytes_per_s descending and truncated to `top_n` if + given - the point of this is usually "what are the biggest + contributors", not a complete listing. + """ + elapsed = (self.stopped_at or time.time()) - (self.started_at or time.time()) + if elapsed <= 0: + return {} + with self._lock: + snapshot = {name: list(buf["values"]) for name, buf in self._buffers.items()} + out = {} + for name, values in snapshot.items(): + n_points = len(values) + if not n_points: + continue + try: + arr = np.asarray(values[-1]) + n_elements = int(arr.size) or 1 + bytes_per_point = int(arr.nbytes) or arr.itemsize + except Exception: + # a value numpy cannot characterise at all (rare) - still + # worth a rough entry rather than silently dropping the + # channel from the report. + n_elements, bytes_per_point = 1, 8 + rate_hz = n_points / elapsed + out[name] = { + "n_points": n_points, + "rate_hz": rate_hz, + "n_elements": n_elements, + "bytes_per_point": bytes_per_point, + "projected_bytes_per_s": rate_hz * bytes_per_point, + } + out = dict( + sorted(out.items(), key=lambda kv: -kv[1]["projected_bytes_per_s"]) + ) + if top_n: + out = dict(list(out.items())[:top_n]) + return out + def report(self, with_channels=False): elapsed = (self.stopped_at or time.time()) - (self.started_at or time.time()) counts = self._final_counts if self._final_counts is not None else { name: len(b["values"]) for name, b in self._buffers.items() } n_points = sum(counts.values()) + # Which of the failed-to-attach channels belong to a *required* + # namespace component - the recording equivalent of /health's + # failed_required, same "everyone else failing is expected, this + # failing is not" distinction. + failed_required = sorted( + {n for n in self._attach_failed_names + if n.split(".", 1)[0] in self._required_names} + ) rep = { "recording_id": self.recording_id, "pgroup": self.pgroup, @@ -1305,6 +1397,8 @@ class RecordingSession: # raises is counted in n_attach_failed, not silently folded in. "n_channels_attached": self.n_attached, "n_attach_failed": self.n_attach_failed, + "failed_required": failed_required, + "n_failed_required": len(failed_required), "n_seeded": self.n_seeded, "n_backfilled": self.n_backfilled, "n_updates": self.n_updates, diff --git a/tests/test_daq_status_server.py b/tests/test_daq_status_server.py index 0c150d3..b63c931 100644 --- a/tests/test_daq_status_server.py +++ b/tests/test_daq_status_server.py @@ -526,6 +526,19 @@ def test_start_scan_monitoring_starts_a_recording_named_for_the_run(): ) +def test_start_scan_monitoring_warns_about_failed_required_channels(capsys): + client = HealthClient() + client.start_recording = lambda **kw: { + "n_channels_attached": 100, "n_channels_requested": 120, + "failed_required": ["daq.something"], + } + daq = _daq_fresh(client) + scan = FakeScan(runno=42) + daq.start_scan_monitoring(scan) + out = capsys.readouterr().out + assert "REQUIRED" in out and "daq.something" in out + + def test_start_scan_monitoring_is_a_noop_without_a_status_server(): daq = _daq_fresh(None) daq._status_server = None diff --git a/tests/test_status_server.py b/tests/test_status_server.py index bf79a30..4212525 100644 --- a/tests/test_status_server.py +++ b/tests/test_status_server.py @@ -969,6 +969,16 @@ class MonitorableDetector(FakeDetector): return FakeMonitor(func, pv=self._fake_pv) +class AttachFailingDetector(FakeDetector): + """Monitorable (has the method, so isinstance(ts, MonitorableValueUpdate) + is True and it lands in _monitorable) but attaching always fails - a + demoted/disconnected-channel stand-in, distinct from not being + monitorable at all.""" + + def set_current_value_callback(self, func="accumulate", **kwargs): + return None + + @pytest.fixture def recording_store(fake_module): FakeMonitor.instances = [] @@ -985,12 +995,13 @@ def recording_store(fake_module): return store -def _recording_store_with(fake_module, detectors): +def _recording_store_with(fake_module, detectors, **fake_module_kwargs): """Like `recording_store`, but with caller-chosen detectors - for tests that need specific FakePV configurations (auto_monitor/connected) per - channel.""" + channel, or a specific required_names() (fake_module_kwargs, e.g. + required=(...)).""" FakeMonitor.instances = [] - name, mod = fake_module() + name, mod = fake_module(**fake_module_kwargs) mod.namespace.status_collection = FakeStatusCollection(detectors) store = _store(name) assert store.wait_ready(timeout=10) @@ -1141,6 +1152,133 @@ def test_a_composed_virtual_channel_is_seeded_for_free(fake_module): assert stopped["data"]["fake.composed"]["values"] == [3.0] +# -------------------------------------------------------------------------- +# failed_required: the recording equivalent of /health's failed_required - +# a channel that fails to attach and belongs to a required namespace +# component is reported separately, same "expected vs not" distinction. + + +def test_recording_reports_failed_required_channels(fake_module): + store = _recording_store_with( + fake_module, + [ + AttachFailingDetector("required_comp.a", 1.0, channel="PV:A"), + AttachFailingDetector("optional_comp.b", 2.0, channel="PV:B"), + MonitorableDetector("required_comp.c", 3.0, channel="PV:C"), + ], + required=("required_comp",), + ) + session = store.start_recording("r1") + rep = session.report() + assert rep["n_attach_failed"] == 2 + assert rep["failed_required"] == ["required_comp.a"] + assert rep["n_failed_required"] == 1 + + +def test_recording_failed_required_is_empty_when_nothing_required_failed( + fake_module +): + store = _recording_store_with( + fake_module, + [ + AttachFailingDetector("optional_comp.b", 2.0, channel="PV:B"), + MonitorableDetector("required_comp.c", 3.0, channel="PV:C"), + ], + required=("required_comp",), + ) + session = store.start_recording("r1") + rep = session.report() + assert rep["failed_required"] == [] + assert rep["n_failed_required"] == 0 + + +# -------------------------------------------------------------------------- +# size_report: projected bandwidth per channel (frequency * shape * +# bitdepth), to judge storage/bandwidth cost from a short trial recording + + +def test_size_report_computes_rate_times_value_size(recording_store): + import numpy as np + + recording_store.start_recording("r1", names=["fake.m1"]) + mon = FakeMonitor.instances[0] + for _ in range(10): + mon.push(np.zeros(4, dtype=np.float64)) # 4 elements * 8 bytes = 32 + session = recording_store._recordings["r1"] + session.started_at -= 2.0 # pretend 2s elapsed, for an exact rate + + rep = session.size_report() + assert rep["fake.m1"]["n_points"] == 10 + assert rep["fake.m1"]["rate_hz"] == pytest.approx(5.0, rel=0.01) + assert rep["fake.m1"]["n_elements"] == 4 + assert rep["fake.m1"]["bytes_per_point"] == 32 + assert rep["fake.m1"]["projected_bytes_per_s"] == pytest.approx(160.0, rel=0.01) + + +def test_size_report_skips_channels_with_no_points_yet(recording_store): + recording_store.start_recording("r1") + session = recording_store._recordings["r1"] + assert session.size_report() == {} + + +def test_size_report_sorts_biggest_contributor_first(recording_store): + import numpy as np + + recording_store.start_recording("r1") + m1, m2 = FakeMonitor.instances + m1.push(np.zeros(1)) # small + m2.push(np.zeros(1000)) # big + session = recording_store._recordings["r1"] + + rep = session.size_report() + assert list(rep.keys())[0] == "fake.m2" + + +def test_size_report_top_n_truncates(recording_store): + import numpy as np + + recording_store.start_recording("r1") + for mon in FakeMonitor.instances: + mon.push(np.zeros(1)) + session = recording_store._recordings["r1"] + + assert len(session.size_report(top_n=1)) == 1 + + +def test_recording_report_endpoint_includes_size_on_request( + recording_store, tmp_path +): + import numpy as np + + config = NamespaceServerConfig(module_name=recording_store.module_name) + app = create_namespace_app(config, store=recording_store) + client = app.test_client() + + client.post("/recording/start", json={"recording_id": "r1"}) + FakeMonitor.instances[0].push(np.zeros(4, dtype=np.float64)) + + plain = client.get("/recording/r1").get_json() + assert "size_per_channel" not in plain + + sized = client.get("/recording/r1?size=1").get_json() + assert "fake.m1" in sized["size_per_channel"] + assert sized["size_per_channel"]["fake.m1"]["bytes_per_point"] == 32 + + +def test_client_recording_size_round_trips(live_server): + """live_server's FakeNamespace has no monitorable channels wired up for + recording, so this only checks the request shape/plumbing, not real + numbers - see the fake_module-based tests above for that.""" + from eco.status_server.client import StatusServerClient + + url, store, app, _ = live_server + client = StatusServerClient(url) + client.wait_ready(timeout=30, poll=0.05) + client.start_recording("r1") + body = client.recording("r1", size=True, size_top_n=5) + assert "size_per_channel" in body + + # -------------------------------------------------------------------------- # backfill: opportunistically fill a still-empty channel from a status # snapshot that was already being taken for another reason (a scan's own @@ -2106,3 +2244,25 @@ def test_the_client_stays_quiet_when_nothing_required_failed(capsys): assert warn_failed_required({"failed_required": [], "failed_names": ["x"]}) == [] assert warn_failed_required({}) == [] assert capsys.readouterr().out == "" + + +def test_the_client_warns_in_red_about_recording_failed_required(capsys): + from eco.status_server.client import warn_recording_failed_required + + warned = warn_recording_failed_required( + {"failed_required": ["daq.something"]} + ) + out = capsys.readouterr().out + assert warned == ["daq.something"] + assert "REQUIRED" in out and "daq.something" in out + assert "\x1b[" in out, "should be colourised" + # deliberately does not suggest reinit() - see the function's docstring + assert "reinit" not in out + + +def test_the_client_stays_quiet_when_no_recording_required_channel_failed(capsys): + from eco.status_server.client import warn_recording_failed_required + + assert warn_recording_failed_required({"failed_required": []}) == [] + assert warn_recording_failed_required({}) == [] + assert capsys.readouterr().out == "" diff --git a/tests/test_status_server_namespace_component.py b/tests/test_status_server_namespace_component.py index b307b19..0f9f092 100644 --- a/tests/test_status_server_namespace_component.py +++ b/tests/test_status_server_namespace_component.py @@ -1,11 +1,14 @@ """eco.status_server.namespace_component.StatusServer: the namespace-level handle for a long-running status server (bernina.status_server, alongside daq/scans) - control, inspection, and the recording settings as real -AdjustableMemory children. +AdjustableFS children (filesystem-based, so another process reading the +same shared config tree sees a changed setting with no REST call needed). The underlying StatusServerClient is monkeypatched out entirely - these tests are about StatusServer's own delegation/settings/gui-launch logic, -not the HTTP client (already covered in test_status_server.py). +not the HTTP client (already covered in test_status_server.py). The +settings' config_dir is pointed at tmp_path, never the real shared +eco_cnf_bernina tree. """ import subprocess @@ -16,7 +19,7 @@ from eco.status_server.namespace_component import StatusServer @pytest.fixture -def server(monkeypatch): +def server(monkeypatch, tmp_path): calls = {} class FakeClient: @@ -50,14 +53,15 @@ def server(monkeypatch): calls["reinit"] = {"mode": mode, "wait": wait, **kwargs} return {"status": "ok"} - s = StatusServer("http://fake:8091", name="status_server") + s = StatusServer("http://fake:8091", name="status_server", config_dir=tmp_path) s._client = FakeClient("http://fake:8091") s._calls = calls return s # -------------------------------------------------------------------------- -# settings: real AdjustableMemory children, not yet consumed by Daq +# settings: real AdjustableFS children (filesystem-based), not yet +# consumed by Daq or the server def test_recording_settings_have_sensible_defaults(server): @@ -69,12 +73,31 @@ def test_recording_settings_have_sensible_defaults(server): def test_recording_settings_are_settable(server): - server.recording_mode.set_target_value("all") - server.recording_max_value_elements.set_target_value(1024) + # set_target_value(hold=False, the default) starts the write on a + # background thread and returns immediately - wait() before asserting, + # same as any other Changer-backed Adjustable. + server.recording_mode.set_target_value("all").wait() + server.recording_max_value_elements.set_target_value(1024).wait() assert server.recording_mode.get_current_value() == "all" assert server.recording_max_value_elements.get_current_value() == 1024 +def test_a_setting_changed_in_one_process_is_visible_in_another(tmp_path): + """The actual point of AdjustableFS over AdjustableMemory: a second + StatusServer instance (standing in for a second session, or the server + process itself, reading the same shared config tree) sees a value + changed by the first with no communication between the two at all - + just the shared filesystem.""" + a = StatusServer("http://fake:8091", name="a", config_dir=tmp_path) + b = StatusServer("http://fake:8091", name="b", config_dir=tmp_path) + + a.recording_mode.set_target_value("sample").wait() + assert b.recording_mode.get_current_value() == "sample" + + b.recording_max_value_elements.set_target_value(2048).wait() + assert a.recording_max_value_elements.get_current_value() == 2048 + + # -------------------------------------------------------------------------- # control: delegates straight to the client