Skip to content

friglet-tray: bind the test fakes' sockets before spawning (SNB-679) - #54

Closed
setavenger wants to merge 4 commits into
integrationfrom
snb-679-tray-fake-bind-race
Closed

setavenger wants to merge 4 commits into
integrationfrom
snb-679-tray-fake-bind-race

Conversation

@setavenger

@setavenger setavenger commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #51; review only the commits after it.

Fixes SNB-679 (Bug, test-only). Net −9 lines (8 added, 17 removed).

What and why

The fake daemons in the lib.rs tests (spawn_stoppable_fake_daemon) and in tests/lifecycle_e2e.rs (spawn_fake_daemon_with) bound their socket inside the task they spawned. Every test that started one then slept a fixed 100 ms, hoping the bind had happened by then. The helpers now call friglet_ipc::listen before spawning the accept loop, so the socket is up when they return. The eleven 100 ms sleeps are gone: eight in lib.rs, three in the e2e file.

The 500 ms delay in spawns_and_connects_when_socket_comes_up stays. It is deliberate: it simulates a daemon that binds late.

Why behaviour is unchanged

Test-only. Each test asserts what it did before. The fakes answer the same way, and the Shutdown path of the stoppable fake (stop listening, remove the socket) is unchanged.

Verification

  • The sleeps were what kept the old helpers working. Experiment, not committed: with the old helpers (bind inside the task) and the sleeps removed, 9 tests fail every run. In lib: retry_keeps_child_when_socket_reachable, attach_adopts_daemons_self_reported_ownership, a_poll_of_the_stopping_daemon_keeps_it_stopped, stop_daemon_stops_an_attached_external_daemon_for_good, stop_daemon_on_a_tray_spawned_daemon_is_not_undone_by_the_supervisor, supervisor_records_crash_and_schedules_restart. In e2e: attach_beats_setup_check_when_daemon_reachable, attach_carries_daemons_self_reported_ownership, quit_shuts_daemon_down_only_when_spawned_by_tray. They connect before the bind. With the new helpers and no sleeps, all pass.

  • Under parallel load: 8 concurrent loops of 15 runs each (120 runs per binary), before (friglet-tray: drop duplicate test fakes and tests (SNB-672) #51) and after. Before: lib 0/120 failures, e2e 0/120. After: lib 0/120, e2e 0/120. The race was not observed before the fix either, as the issue says.

  • Tray test time (5 runs each, debug build):

    before (friglet-tray: drop duplicate test fakes and tests (SNB-672) #51) after
    lib test binary wall time 2.48–2.49 s 2.27 s
    e2e test binary wall time 0.50–0.51 s 0.50–0.51 s
    the 7 lib tests that slept, run one at a time (one slept twice) 3.45 s 2.63 s
    the 3 e2e tests that slept, run one at a time 0.33 s 0.03 s

    The lib binary is bound by stop_daemon_stops_an_attached_external_daemon_for_good, which went from 2.47 s to 2.26 s; most of that is the production 2 s "look once more" wait in stop_daemon. The e2e binary is bound by the deliberate 500 ms delay. Both before and after, the spawn test sometimes takes 0.75 s, depending on where its 500 ms delay lands against the 250 ms connect poll.

  • cargo check --workspace --all-targets --all-features: 0 warnings.

  • cargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings: clean.

  • cargo fmt -p friglet -p friglet-ipc -p friglet-tray -- --check: clean.

  • cargo test --workspace: 251 passed, 1 ignored, 0 failed (same as friglet-tray: drop duplicate test fakes and tests (SNB-672) #51).

setavenger and others added 4 commits October 3, 2026 08:46
Three lifecycle e2e tests wrote a shell script to a temp dir and then ran
it as the "daemon binary". The test harness runs tests on parallel
threads of one process, so another test's spawn could fork while the
script was still open for writing; the forked child holds that write
handle until it execs, and running the script in that window fails with
"Text file busy" (ETXTBSY, os error 26).

The scripts are now committed as executable fixtures under
friglet-tray/tests/fixtures/ and located via CARGO_MANIFEST_DIR, so
nothing is written while the tests run. The long-running fixture uses
`exec sleep 30`, so killing the spawned child no longer leaves a stray
sleep behind for 30 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…NB-667)

Nothing here changes what the tray does:

- Tauri commands set_config and set_scan_key: registered, but the UI
  has saved settings through apply_settings since 8bf4c40 and never
  invokes them. The SetConfig / SetScanKey protocol requests stay
  (wire compatibility with separately installed daemons).
- lifecycle: decide/Action (used only by its own test), attach_or_spawn
  (no callers) and QuitAction/quit_action (an enum around one bool;
  perform_quit now tests the bool).
- show_settings_window / show_wallet_window were copies differing only
  in the tab: one show_window_tab(app, tab). The
  FRIGLET_TRAY_SHOW_ON_START parse is a pure function of the value, so
  its test no longer sets the process environment (the unsafe set_var's
  safety comment was false: tests run in parallel).
- get_config and send_with_note share one daemon_request helper
  (connect, request, map errors); the poller and the poll_once test
  helper share record_poll.
- ErrorBook::event returned "should be logged", which its only caller
  ignored; it returns nothing now. Doc links point at the constants
  that exist (STALL_GRACE_SECS, UNREACHABLE_GRACE_SECS).
- fake-daemon example: uses friglet_ipc's NETWORKS and one scan-key
  check instead of copies.
- UI: CSS rules already covered by `[hidden] { display: none
  !important; }`, a `.hint code` rule that matches nothing, and an
  unused id="recent-errors".
- tauri.conf.json: the bundle.linux.deb.depends block. The Tauri CLI
  adds libwebkit2gtk-4.1-0 and the appindicator package itself (with
  tauri's tray-icon feature on) and does not de-duplicate, so the .deb
  listed both packages twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- lib.rs tests: spawn_fake_daemon / spawn_fake_daemon_owned were a
  second fake next to spawn_stoppable_fake_daemon, differing only in
  canned GetStatus fields no test reads. Their four users never send
  Shutdown or check the pid, so they now use the one fake.
- lifecycle_e2e: attaches_when_daemon_already_running is covered by
  attach_carries_daemons_self_reported_ownership, which attaches the
  same way (the locator panics if consulted) and also checks the
  carried ownership.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fake daemons in the lib tests and the lifecycle e2e tests bound
their socket inside the task they spawned, so every test slept a fixed
100 ms after starting one and hoped the bind had happened by then. The
helpers now bind (friglet_ipc::listen) before spawning the accept loop
and return with the socket up, and the eleven sleeps are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@setavenger

Copy link
Copy Markdown
Owner Author

Merged into integration through #71 on 2026-10-11 (the user live-tested the combined stack first). GitHub's stacked-PR merge rebased the stack, so this PR's commits landed with new IDs and GitHub can't mark it merged itself. The code is identical: integration now has the same tree as the tested branch friglet-deslop-live-test (08bf11d), which contains this PR's head. Closing as merged via #71.

@setavenger setavenger closed this Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant