trilium/apps/server/spec/support
Elian Doran 8e05dbac20
perf(healthcheck): probe with a shell script instead of starting node
Until February 2023 the healthcheck was thirteen lines of wget. It was
rewritten in node so it could read the configuration, and the cost of
starting a runtime every interval came with it. That cost, not the
bundle that grew around it later, is what the CPU spike reports were
measuring: the bundle only arrived in 2025 and made an existing problem
about five times worse.

Node is no longer needed to read the configuration, because the server
records where it is listening once it has bound. It writes the address
from httpServer.address() rather than the one that was configured, so
the probe follows what actually happened, and the file existing at all
means the server reached the point of listening.

The probe is then ten lines of shell with nothing to resolve. Measured
against a real instance in all three listening modes:

  http           http://127.0.0.1:18081/...    up 0, killed 1
  https          https://127.0.0.1:18443/...   up 0, killed 1
  unix socket    url and socket path apart     up 0

  cpu   ~30 ms  ->  9.5 ms per probe

curl rather than wget: neither GNU nor busybox wget can reach a unix
socket, which Trilium supports and which would have broken silently.
All five images therefore install curl, and all five now invoke the same
script — which incidentally fixes the rootless images, whose healthcheck
has called docker_healthcheck.js since May 2025 while the build emitted
.cjs, failing with MODULE_NOT_FOUND on every run.

Two defects surfaced only once the tests drove the real script. curl's
--fail treats a 3xx as success, where the node probe required exactly
200, so the status is now compared explicitly. And the TLS fixture had
to be reissued as RSA: the curl macOS ships links LibreSSL 3.3.6, which
cannot complete an EC handshake against node's TLS, so the certificate
test passed in CI and failed on every mac.

The suite keeps its shape. Six unit tests cover the publisher, and seven
drive the shipped script itself against real servers, so the exit codes
asserted are the ones docker reads. They skip on Windows, which costs
nothing while every CI suite runs on ubuntu. healthcheck.ts is at 100%
lines and branches.

Not verified here, for want of a container: the package installs, the
probe running under gosu against files the server owns, and the image
size. CI covers the first two on Dockerfile and Dockerfile.alpine only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 19:31:36 +03:00
..
internal_api.ts test(server): basic coverage of some core routes 2026-05-29 20:56:53 +03:00
self_signed_tls.ts perf(healthcheck): probe with a shell script instead of starting node 2026-08-23 19:31:36 +03:00