diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04e17bb7..9691e480 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -157,7 +157,10 @@ jobs: POSTGRES_PASSWORD: postgres ports: - 5432:5432 + # Its data is in memory: every test makes and drops a database, and + # waiting for the disk to sync each one is most of what that costs. options: >- + --tmpfs /var/lib/postgresql/data --health-cmd pg_isready --health-interval 5s --health-timeout 5s @@ -169,7 +172,12 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 - run: cargo clippy --locked -p meshrmm-server --all-targets -- -D warnings + # The tests' data directories and SQLite databases are in memory too: + # the server syncs its key, its database and each checkpoint to the + # disk, which on a real disk takes longer than the tests themselves. - run: cargo test --locked -p meshrmm-server + env: + TMPDIR: /dev/shm - run: python3 -m unittest discover -s scripts/tests -v - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: diff --git a/Cargo.toml b/Cargo.toml index 9e8e31ce..fc832d25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,14 @@ dbg_macro = "deny" todo = "deny" unimplemented = "deny" +# Unoptimized, Argon2 takes about a third of a second for each password, and +# the server's tests hash one for every account they create. +[profile.dev.package.argon2] +opt-level = 3 + +[profile.dev.package.blake2] +opt-level = 3 + [profile.server-release] inherits = "release" codegen-units = 1 diff --git a/docs/development.md b/docs/development.md index ea624a06..1d9e0dc6 100644 --- a/docs/development.md +++ b/docs/development.md @@ -224,6 +224,14 @@ sh scripts/test-server-postgres.sh # arguments go to cargo test It starts a throwaway PostgreSQL in a temporary directory, which needs only PostgreSQL's `initdb` and `pg_ctl` installed, and removes it afterwards. + +Each test starts a server of its own in a temporary directory, and that +server syncs its key, its database and each checkpoint to the disk. On a real +disk those waits are most of the tests' time, so on Linux keep the +directories in memory: `TMPDIR=/dev/shm cargo test --locked -p +meshrmm-server` takes about half as long. The script above and CI do that +already, and CI keeps its PostgreSQL's data in memory as well. + `tests/schema_parity.rs` checks that the two backends' migrations make the same tables and columns; change both `server/migrations/sqlite` and `server/migrations/postgres` together. diff --git a/scripts/test-server-postgres.sh b/scripts/test-server-postgres.sh index 545428e8..74abbfff 100755 --- a/scripts/test-server-postgres.sh +++ b/scripts/test-server-postgres.sh @@ -8,11 +8,19 @@ # Debian's packages put them. The cluster lives in a temporary directory, # listens only on 127.0.0.1 (port 54329, or MESHRMM_TEST_POSTGRES_PORT) and is # removed when the tests end. +# +# Where the system has /dev/shm (Linux), the cluster and the tests' own data +# are kept there, in memory, unless TMPDIR says where to put them: waiting +# for a real disk to sync them takes longer than the tests themselves. set -eu SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) ROOT_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd) PORT=${MESHRMM_TEST_POSTGRES_PORT:-54329} +if [ -z "${TMPDIR:-}" ] && [ -d /dev/shm ] && [ -w /dev/shm ]; then + TMPDIR=/dev/shm + export TMPDIR +fi if ! command -v initdb >/dev/null 2>&1; then if command -v pg_config >/dev/null 2>&1; then