Skip to content

Run an isolated platform for end-to-end tests

End-to-end tests for an application want a real platform: real tokens, real sign-in, real deliveries. They should not use a developer’s own fcdev, whose data the tests would change, nor a shared environment. The answer is a second fcdev, started just for the tests, with nothing in common with the first except, optionally, the PostgreSQL server.

The platform repository’s scripts/e2e-platform.sh is a worked example of this recipe (up, verify, status, env, down, drop). The steps below are what it does, generalised.

Shared by default Give the test instance
Ports 8080, 9090, 8095, 8096, 8091, 8090 Its own API and metrics ports; turn the rest off
The database Its own database (next section)
The PID file --pid-file <state>/fcdev.pid
JWT signing key and application key (kept beside the database) Follow the database path, or set FC_JWT_SIGNING_KEY_PATH and FLOWCATALYST_APP_KEY
The fcdev fn and MCP credential files in the user cache directory HOME and XDG_* pointed into the state directory, or FC_FN_CLI_CREDENTIALS_PATH and FC_MCP_CREDENTIALS_PATH
FC_* variables in your shell Start it with a clean environment (env -i)

Without the last two, a test instance silently overwrites the credential files your own fcdev tools use.

A separate database in the cluster you already run (cheapest). Create it, and point the test instance at it:

Terminal window
psql "postgresql://postgres:postgres@localhost:15432/flowcatalyst" -c 'CREATE DATABASE e2e_orders'
DB="postgresql://postgres:postgres@localhost:15432/e2e_orders?sslmode=disable&pool_max_conns=8"

Each database has its own catalog, migration history, advisory-lock key space and LISTEN/NOTIFY channels, so the two platforms cannot interfere. Cap connections (pool_max_conns in the URL, FC_SCHEDULER_DB_MAX_CONNECTIONS=4): the instances share the server’s max_connections.

Do not use a separate schema in the same database: the migration bootstrap looks up its tables by name across every schema, finds the other platform’s migration ledger, and either fails or skips every migration and works on the other platform’s tables.

Its own embedded cluster (fully independent, for CI or when nothing else is running): give it a data path and port instead of a URL (--embedded-db-path <state>/pg --embedded-db-port 25432).

Terminal window
STATE=$PWD/tmp/e2e
mkdir -p "$STATE/home"
env -i PATH="$PATH" HOME="$STATE/home" \
FLOWCATALYST_BOOTSTRAP_ADMIN_EMAIL=admin@e2e.test \
FLOWCATALYST_BOOTSTRAP_ADMIN_PASSWORD="$(openssl rand -base64 18)" \
FC_SCHEDULER_DB_MAX_CONNECTIONS=4 \
fcdev start \
--database-url "$DB" \
--api-port 18080 --metrics-port 19090 \
--functions=false --ingestor=false --mcp=false \
--pid-file "$STATE/fcdev.pid" \
> "$STATE/fcdev.log" 2>&1 &
until curl -fs http://localhost:18080/health >/dev/null; do sleep 1; done

The migrations run on first start and the bootstrap administrator is created from the two variables (keep the generated password for the tests that sign in as an administrator). With --database-url, the keys are stored next to the default data path inside the isolated HOME; set FC_JWT_SIGNING_KEY_PATH and FLOWCATALYST_APP_KEY explicitly if you prefer. Leave on only what the tests need: the router, the dispatch scheduler, the scheduled-job scheduler and the stream processor are on by default, and the outbox processor is off.

Seed through the same interfaces production uses, so the tests exercise them:

  1. The application and its service account:

    Terminal window
    env -i PATH="$PATH" HOME="$STATE/home" fcdev init --yes \
    --database-url "$DB" --root "$STATE" \
    --code orders --name "Orders" --api-base-url http://localhost:18080

    This writes $STATE/.env with the client id and secret, and creates the default client. (fcdev init reads the application key the same way fcdev start does, so run it with the same HOME.)

  2. Definitions: run your application’s own definition sync against http://localhost:18080 with those credentials (event types, roles, connections, subscriptions, pools, scheduled jobs).

  3. Clients and users the tests need, through the API as the administrator: a test client with your application enabled, a client-tier user holding your roles, and so on.

  4. A login client if the tests sign people in: POST /api/applications/{id}/provision-login-client with your test callback URLs (both localhost and 127.0.0.1 if your tests use both). A public client needs no secret.

  5. The signing secret if your receiver verifies deliveries: regenerate it on the application’s service account and give it to the application under test.

Make the seeding idempotent so the same command can run against an instance that is already up.

Load the generated values into the application’s environment: FLOWCATALYST_BASE_URL, FLOWCATALYST_CLIENT_ID, FLOWCATALYST_CLIENT_SECRET, the signing secret, and for sign-in the login client id with the issuer http://localhost:18080 (the application framework needs APP_ENV=local or test to accept plain http). If the application keeps its own database, give it its own too; never point it at the platform’s.

A useful smoke test, before the application’s own suite:

  • GET /health answers;
  • a client-credentials token can be minted with the seeded credentials;
  • a sign-in through the login client returns the expected roles;
  • a dispatch job or event reaches a throwaway receiver, signed, and ends COMPLETED.
Terminal window
fcdev stop --pid-file "$STATE/fcdev.pid"
psql "postgresql://postgres:postgres@localhost:15432/flowcatalyst" -c 'DROP DATABASE e2e_orders WITH (FORCE)'
rm -rf "$STATE"

Guard the drop by name (for example only names starting e2e_), so a mistyped variable can never drop someone’s real database.

  • Clients created after start. The router reads its configuration (which client queues to consume) at start and every 5 minutes. After creating a client, reload it (POST /router/config/reload as the administrator) or jobs for that client wait QUEUED.
  • Signing. Deliveries are signed by the service account the connection, or the job code’s application, resolves to. A job whose code belongs to an application without a service account is delivered unsigned, and a verifying receiver refuses it.
  • It is still fcdev. The test-principal header is honoured, the debug endpoints are on, and loopback and private delivery targets are allowed. Fine for tests; never expose it.
  • Clocks and timeouts. Tests that wait for deliveries should poll for the job’s final status rather than sleep for a fixed time; the dispatch scheduler and router poll on short intervals but not instantly.