Repository navigation
CBSE-24138: Make the unit suite runnable on Windows - #375
celticht32 wants to merge 1 commit into
Conversation
1412361 to
10a89fd
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are blocking approval.
No open issues 🎉
What changed in this PR
This test-only PR makes the unit suite collect and run on Windows without changing server behavior. Existing Windows failures remain outside its scope.
Changes:
- Preserve the parent environment for SDK-isolation subprocesses while explicitly setting
PYTHONPATH. - Guard the Unix-only
pwdimport and skip the two POSIX identity tests on Windows. - Replace RSS measurements with cross-platform
tracemallocmeasurements and tighten the streaming-memory threshold.
| File | Description |
|---|---|
tests/unit/test_sdk_isolation.py |
Inherits the environment so probe subprocesses can start on Windows. |
tests/unit/test_audit_integration_points.py |
Guards pwd and adds Windows skips for POSIX-specific tests. |
tests/unit/operational/test_reference_tools_unit.py |
Uses tracemalloc to check streaming memory usage across platforms. |
Review effort: Balanced
69138f6 to
0de546f
Compare
|
Updated: rebased onto current main (45e8b32) and addressed the review comments, with a reply on each thread. No code change, rebase only. Unit tests: 2258 passed on Linux, ruff format --check and ruff check clean. |
f3306b7 to
44f4c13
Compare
|
Updated this PR. It now makes the full unit suite pass on Windows, not just most of it. The audit sink part is tracked in #383. Added since the last push:
Verification: |
Four independent defects, all in tests, none touching src. The first three make the unit suite unrunnable on Windows, so a contributor on that platform cannot verify anything before opening a pull request. Each is a module-scope import or a hardcoded POSIX value, and because a collection error is fatal, any one of them takes the whole suite down rather than the file it is in. The fourth makes one test fail there for reasons that are not the product's. test_audit_integration_points.py imports pwd at module scope. pwd is Unix-only. cb_mcp/audit/identity.py already guards its own import of it and has a Windows path through getpass, so the product is fine and only the test is not. The import is guarded the same way the source guards it, and the two tests of the twenty-nine that genuinely assert POSIX uid-to-passwd mapping are skipped by platform, because there is no Windows behaviour to assert instead. The other twenty-seven then run there. test_reference_tools_unit.py imports resource at module scope, also Unix-only. Its one use was measuring peak RSS for the streaming invariant, which tracemalloc measures on every platform, so the measurement moves there rather than being skipped off Unix. That also measures the right quantity: peak RSS counts pages the allocator has not returned to the operating system, so it moves for reasons unrelated to whether records were materialised, and it can stay flat when they were. Against allocation the separation is stark, 0.007 MB when streaming against 11.8 MB with records held, so the growth bound tightens from 10.0 MB to 2.0 MB. The old bound sat close enough to the broken value that a smaller dataset could have slipped under it. test_sdk_isolation.py builds its probe subprocess environment by hand with a literal PATH of /usr/bin:/bin. That is not a valid PATH on Windows, so the probe interpreter cannot start and all nine tests in the file fail. What the probe needs to control is PYTHONPATH, which is still set explicitly; the rest of the environment is now inherited. test_workers_smoke.py fails on Windows in two ways that are both in the test. Its fixture stops the server with send_signal(SIGINT), which Windows Python rejects for a child process (ValueError: Unsupported signal), so teardown errors and the kill that follows never runs. And it compares the pid of the process it started with the pids in the log file names. On Windows the console script is a launcher that starts the real Python process, so the test holds the launcher's pid while the logs carry the Python process's, and the check fails after every earlier assertion has passed. Teardown now ends the whole process tree with taskkill /T on Windows and keeps SIGINT elsewhere. The supervisor-pid check is skipped on Windows only; the check that exactly one supervisor and one process per worker each wrote their own log files still runs everywhere.
44f4c13 to
6f060a4
Compare
Related Issue
Resolves: CBSE-24138 (https://couchbasecloud.atlassian.net/browse/CBSE-24138)
Server(s) Affected
operational)operational-insights)Almost entirely a test change. The one change under
src/is in the audit sink (see below).What does this change do?
The unit suite could not run on Windows. It failed during collection, before any test executed, because three modules import Unix-only standard library modules at module scope:
tests/unit/test_sdk_isolation.pyresourcetests/unit/operational/test_reference_tools_unit.pyresourcetests/unit/test_audit_integration_points.pypwdA collection error aborts the whole run, so a contributor on Windows had no way to verify a change before opening a pull request. The imports are now guarded and only the tests that cannot work on Windows are skipped: two tests that assert POSIX uid-to-passwd mapping. Everything else runs on both platforms.
Two further changes make the whole suite pass on Windows:
tests/unit/test_workers_smoke.py: the test could not stop its server on Windows.Popen.send_signal(SIGINT)is not supported there, and the console script is a launcher whose process id is not the Python process's. It now ends the process tree withtaskkill /Tand skips the supervisor pid assertion on Windows. The check that the supervisor and each worker write their own log files still runs.src/cb_mcp/audit/sink.py: the sink opened its log in text mode, so on Windows every \n was written as \r\n while rotation counted the bytes it meant to write. Measured over the same 20 records: 1920 counted and 1920 on disk on Linux, 1920 counted and 1940 on disk on Windows, so rotation fired late. The fouropen()calls now usenewline="", so records are written exactly as emitted on every platform. There is no change on Linux or macOS. Tracked in AuditSink writes CRLF on Windows, so its rotation size count is wrong #383.Why is this change needed?
A contributor on Windows cannot verify a change before opening a pull request, and two audit-sink rotation tests failed there because of a real defect in the sink.
Evidence of Testing
The 2 Windows skips are
test_local_identity_ignores_the_caller_controlled_environmentandtest_local_identity_falls_back_to_the_numeric_uid_without_a_passwd_entry, both POSIX uid-to-passwd mapping. They run on Linux, and CI is ubuntu-latest throughout.No cluster runs: nothing here touches cluster-facing code. Manual verification with an MCP client: not applicable.
Worth considering separately: every job in
.github/workflowsruns onubuntu-latest, so nothing prevents the next Unix-only import landing the same way. Awindows-latestentry on the test matrix would. Out of scope here.Compatibility Considerations
The audit sink now writes log lines with a bare newline on Windows, as it already did elsewhere. No tool, flag, environment variable or dependency changes. One commit on main 45e8b32; no dependency on other PRs.
Checklist