Ray's Knowledge Base
Unlock

Measure the RSS of rmaestro ui with 8 idle shell panes in a pty test

RecipeVerified 31 Oct 2026Holds anywhere
Recipe. When to use it, the steps, and what showed that they work.

When to use#

You write or change an integration test that runs the real rmaestro ui binary, for example a memory budget test. The UI refuses to start unless stdin and stdout are terminals, so it needs a pseudo terminal (pty).

Steps#

  1. Put the test in crates/rmaestro-cli/tests/it/ui_rss.rs and add mod ui_rss; to tests/it/main.rs. 2. Use the isolated state folders and the daemon start from tests/it/support.rs. Never touch the user's real daemon. 3. Open the pty with nix::pty::openpty at 200x60. Enable the nix term feature with cargo add --dev nix -F term if it is missing. Set TERM=xterm-256color. 4. Read the pty master all the time on a thread, or the UI blocks on a full pty buffer. 5. Open 8 shell panes, then wait for 8 panes through the daemon (not a fixed sleep). 6. Wait 2 seconds idle, then read RSS with ps -o rss= -p <ui pid>. Assert at most 64 MiB and eprintln! the number. 7. Stop the UI and the daemon in a Drop guard, so cleanup runs when the test fails. 8. Also run the test in a plain pty-less shell with a deadline, to check it does not hang. 9. Run rvow prove once before the test exists. The red result is 'ran 0 tests'. Run it again at the end. 10. If RSS is over budget, do not raise the budget. Report what uses the memory and run rvow block.

Evidence#

Task TSK-9wb1q9 on branch perf/heap-budgets. The measured RSS was 17,600 KiB in the first passing run and 17,456 KiB in the plain-shell run, far below the 64 MiB budget. The first draft failed to compile because the raw i32 fds did not match the OwnedFd that nix returns. The fix was to use the OwnedFd values and nix I/O instead of unsafe libc calls.