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.
1. Give it its own everything
Section titled “1. Give it its own everything”| 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.
2. Choose its database
Section titled “2. Choose its database”A separate database in the cluster you already run (cheapest). Create it, and point the test instance at it:
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).
3. Start it
Section titled “3. Start it”STATE=$PWD/tmp/e2emkdir -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; doneThe 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.
4. Seed it
Section titled “4. Seed it”Seed through the same interfaces production uses, so the tests exercise them:
-
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:18080This writes
$STATE/.envwith the client id and secret, and creates thedefaultclient. (fcdev initreads the application key the same wayfcdev startdoes, so run it with the sameHOME.) -
Definitions: run your application’s own definition sync against
http://localhost:18080with those credentials (event types, roles, connections, subscriptions, pools, scheduled jobs). -
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.
-
A login client if the tests sign people in:
POST /api/applications/{id}/provision-login-clientwith your test callback URLs (bothlocalhostand127.0.0.1if your tests use both). A public client needs no secret. -
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.
5. Point the application at it
Section titled “5. Point the application at it”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.
6. Check it end to end
Section titled “6. Check it end to end”A useful smoke test, before the application’s own suite:
GET /healthanswers;- 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.
7. Tear it down
Section titled “7. Tear it down”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.
Caveats
Section titled “Caveats”- 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/reloadas the administrator) or jobs for that client waitQUEUED. - 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.
Related
Section titled “Related”- fcdev day to day (two instances side by side, isolated runs).
- Register an application and declare definitions in code.
- Framework testing: end-to-end kit.