Repository navigation
test: Cover GetStats CPU usage per session in obs-websocket - #2250
Merged
Merged
Conversation
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
zackees
enabled auto-merge
October 24, 2026 22:11
6 of 7 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-websocketbump 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 indocs/features.md. It does not move the submodule.test_ws_cpu_usagecompiles the plugin's request handlers from the submodule against libobs and sendsGetStatsthroughRequestHandler::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 sendGetStatsat 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 underxvfb-runlike the othertest_ws_*tests that start libobs).RED → GREEN
plugins/obs-websocketchecked out at a4df0f3 (ws#19's parent, the fork commit just before the fix; not committed),each_session_measures_its_own_intervalfails on all three lanes: Csession 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_sessionpasses there too (it is the race guard, for TSan).test_ws_cpu_usagepasses 2/2 on C (6.094% / 3.047%), hybrid (6.250% / 3.125%) and libobs-c-reference (6.094% / 3.047%). The other 10test_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_60on C (one field skipped) andtest_pipewire_screencast_shmpacked_rowson hybrid. Both pass when re-run alone. Local gate:--test-diff origin/master66/66 and--lane lintok. Exported symbols: 1766, the same set on all three libraries.Checklist
masterdocs/features.mdis added or updated-W..., ratchets): not applicable(Rebased onto current master, which only brought unrelated commits, as
fb5fed4d4; the runs above name the commits they ran on.)