Skip to content

test: Cover GetStats CPU usage per session in obs-websocket - #2250

Merged
zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:test/ws-cpu-usage
Oct 24, 2026
Merged

zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:test/ws-cpu-usage

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1346

What and why

The fix for #1346 is already on master. obs-rust/obs-websocket#19 gives each websocket session its own locked CPU usage state, and requests without a session share one locked state. It came in with the plugins/obs-websocket bump in #1996 (0d663eefb to 99dd8468b; master's pin 30d6f51 still contains it). The regression test was never posted, so #1346 is still open. This PR adds only the test and the fix's line in docs/features.md. It does not move the submodule.

test_ws_cpu_usage compiles the plugin's request handlers from the submodule against libobs and sends GetStats through RequestHandler::ProcessRequest:

  • each_session_measures_its_own_interval: two sessions. The test burns CPU, polls from session a, idles for as long, then polls from session b. b's interval covers the burn too, so b must report about half of a's usage. When all clients shared one state, b saw only the idle slice.
  • parallel_get_stats_on_one_session: 8 threads send GetStats at once, half with a session and half without. Every reading must be finite and between 0 and 100.

Registered as test/cmocka/tests.d/test_ws_cpu_usage.cmake (Linux, frontend on, nlohmann_json and Qt found; run under xvfb-run like the other test_ws_* tests that start libobs).

RED → GREEN

  • RED: against the pre-fix submodule. With plugins/obs-websocket checked out at a4df0f3 (ws#19's parent, the fork commit just before the fix; not committed), each_session_measures_its_own_interval fails on all three lanes: C session a (burn): 6.094%, session b (burn + idle): 0.000%, hybrid 6.250% / 0.000%, libobs-c-reference 6.250% / 0.000%. parallel_get_stats_on_one_session passes there too (it is the race guard, for TSan).
  • GREEN: at master's pin 30d6f51, test_ws_cpu_usage passes 2/2 on C (6.094% / 3.047%), hybrid (6.250% / 3.125%) and libobs-c-reference (6.094% / 3.047%). The other 10 test_ws_* tests pass on all three lanes. Full ctest (private Xvfb, fresh HOME): C 469/470, hybrid 489/490, no skips. The one failure on each lane was a load timing failure in an unrelated test at load average 35-45: test_deinterlace_2x_field_order_50i_into_60 on C (one field skipped) and test_pipewire_screencast_shm packed_rows on hybrid. Both pass when re-run alone. Local gate: --test-diff origin/master 66/66 and --lane lint ok. Exported symbols: 1766, the same set on all three libraries.
  • Real app: no app change; the fix shipped in plugins/obs-websocket: bump for the parallel RequestBatch notify fix #1996.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (test-only PR: RED shown against the pre-fix submodule, GREEN at master's pin)
  • User-visible change: its line in docs/features.md is added or updated
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite (gate passed locally, head not stamped)
  • Warning or flag changes (-W..., ratchets): not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not applicable

(Rebased onto current master, which only brought unrelated commits, as fb5fed4d4; the runs above name the commits they ran on.)

obs-websocket used to keep one os_cpu_usage_info_t for every client, and
os_cpu_usage_info_query() moves its last times forward on every call. A
client's GetStats reported the CPU usage since the last GetStats from
any client, not since its own, and the query ran without a lock while
requests run in parallel on the thread pool. The fork fix,
obs-rust/obs-websocket#19 (one locked state per session, a shared locked
one for requests without a session), came in with the submodule bump in
obs-rust#1996.

test_ws_cpu_usage sends GetStats through RequestHandler with two
sessions: it burns CPU, polls from session a, idles as long, then polls
from session b. b's interval covers the burn too, so it must report
about half of a's usage. With the submodule at a4df0f3, the commit
before the fix, b reports only the idle slice (0.000% against 6.094%)
and the case fails; at the current pin it reports 3.047%. A second case
sends GetStats from 8 threads at once, with and without a session.

The fix gets its line in docs/features.md.

Fixes obs-rust#1346
@rdoupe
rdoupe requested a review from zackees as a code owner October 24, 2026 22:11
@zackees
zackees enabled auto-merge October 24, 2026 22:11
@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into obs-rust:master with commit 3ef31d4 Oct 24, 2026
37 checks passed
vpacher pushed a commit to vpacher/obs-studio that referenced this pull request Oct 26, 2026
The nightly Sanitizers asan pass (-fsanitize=address,undefined) failed
to link test_ws_cpu_usage: undefined reference to typeinfo for
WebSocketServer (run 40191023688). The request handlers name
WebSocketServer, a QObject whose typeinfo is emitted only beside its moc
output, which the test does not compile; only the vptr check references
it. The test came in with obs-rust#2250.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

obs-websocket: GetStats CPU usage shares one unlocked state across clients (data race, wrong values)

2 participants