This is an automated email from the ASF dual-hosted git repository.
sergehuber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/unomi-tracker.git
The following commit(s) were added to refs/heads/main by this push:
new 92f19dd Run the tracker tests against Unomi 3 and Unomi 4 on every
pull request (#37)
92f19dd is described below
commit 92f19dd417838c7d30ec15148789005a97ca8c21
Author: Serge Huber <[email protected]>
AuthorDate: Tue Nov 3 12:24:10 2026 +0100
Run the tracker tests against Unomi 3 and Unomi 4 on every pull request
(#37)
* Run the tracker tests against each Unomi server on every pull request
A new workflow runs yarn test:servers with one job per name: the
comparison with 1.5.0 and the five servers (Unomi 2.3, 2.7, 3.0, 4.0
multi-tenant and single-tenant). .asf.yaml makes these jobs, and the
existing lint-tests and build jobs, required to merge into main.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Run only Unomi 3 and Unomi 4 on pull requests
The other names (the comparison with 1.5.0, Unomi 2.3 and 2.7, Unomi 4
single-tenant) stay manual, before a release.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Wait until Unomi answers steadily before the server tests
On the slower CI runners, Unomi 4 kept registering its endpoints for a
few seconds after the setup, and some requests answered 404. The setup
now waits for the Unomi 4 health check, then for the endpoints the tests
use to answer five times in a row, two seconds apart.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Wait for the Unomi 4 health check before setting it up
On a CI run, the tenant API key endpoint answered 404 ("No service was
found") right after the tenant was created: Unomi 4 was still starting.
The setup now waits until every part of the health check is LIVE before
creating the tenant, and retries the key generation.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.asf.yaml | 6 ++++
.github/workflows/server-tests.yml | 46 ++++++++++++++++++++++++++
README.md | 2 +-
test/servers/README.md | 5 +--
test/servers/run.js | 2 +-
test/servers/unomi.js | 68 ++++++++++++++++++++++++++++++++++++--
6 files changed, 123 insertions(+), 6 deletions(-)
diff --git a/.asf.yaml b/.asf.yaml
index ab59476..045c0c1 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -12,3 +12,9 @@ github:
- root
restrict_deletion: true
restrict_force_push: true
+ # Job names from .github/workflows (not validated: a wrong name blocks
every merge)
+ required_status_checks:
+ - "lint-tests"
+ - "build"
+ - "server-tests (unomi3)"
+ - "server-tests (unomi4)"
diff --git a/.github/workflows/server-tests.yml
b/.github/workflows/server-tests.yml
new file mode 100644
index 0000000..b4eb9a1
--- /dev/null
+++ b/.github/workflows/server-tests.yml
@@ -0,0 +1,46 @@
+name: Server Tests
+
+# The tracker in a real browser against Unomi 3 and Unomi 4 (test/servers).
+# Each job is a required check for merging into main (.asf.yaml): keep the job
names in sync.
+on:
+ pull_request:
+ types: [opened, reopened, synchronize]
+ push:
+ branches: [main]
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: server-tests-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ server-tests:
+ name: server-tests (${{ matrix.target }})
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ strategy:
+ fail-fast: false
+ matrix:
+ # The other names (compare-1.5.0, unomi2-legacy, unomi2,
unomi4-compat) are run by hand before a release
+ target: [unomi3, unomi4]
+ steps:
+ - uses: actions/checkout@v5
+ - name: Install dependencies
+ shell: bash
+ run: yarn install --frozen-lockfile
+ - name: Install Chromium
+ shell: bash
+ run: npx playwright install --with-deps chromium
+ - name: Run the tests
+ shell: bash
+ run: yarn test:servers ${{ matrix.target }}
+ - name: Upload the test results
+ if: failure()
+ uses: actions/upload-artifact@v4
+ with:
+ name: test-results-${{ matrix.target }}
+ path: test/servers/test-results/
+ retention-days: 7
diff --git a/README.md b/README.md
index b0ea620..c75b761 100644
--- a/README.md
+++ b/README.md
@@ -152,7 +152,7 @@ Releases of other projects must depend on a released
version instead.
Testing
-------
- `yarn test`: unit tests, and a check that the documented configurations
compile against the TypeScript types
-- `yarn test:servers`: browser tests against Unomi 2.x, 3.x and 4.x started
with Docker; not part of CI, see [test/servers](test/servers/README.md)
+- `yarn test:servers`: browser tests against Unomi 2.x, 3.x and 4.x started
with Docker; Unomi 3 and 4 must pass on every pull request, see
[test/servers](test/servers/README.md)
License
-------
diff --git a/test/servers/README.md b/test/servers/README.md
index 23d3f9d..35e6d02 100644
--- a/test/servers/README.md
+++ b/test/servers/README.md
@@ -22,8 +22,9 @@ These tests load the tracker in a real browser (Chromium,
through Playwright) an
each supported Unomi version, started with Docker Compose. They check what
unit tests cannot:
CORS, preflight requests, cookies, API keys and the events actually stored by
the server.
-They are not part of CI. Run them before a release, and whenever you change
how the tracker talks
-to the server.
+`unomi3` and `unomi4` run on every pull request
(`.github/workflows/server-tests.yml`) and must pass
+before merging (`.asf.yaml`). Run all of them before a release, and whenever
you change how the
+tracker talks to the server.
Requirements
------------
diff --git a/test/servers/run.js b/test/servers/run.js
index 8d41235..5930bce 100644
--- a/test/servers/run.js
+++ b/test/servers/run.js
@@ -22,7 +22,7 @@
// yarn test:servers compare-1.5.0 only the comparison with 1.5.0 (no
Docker needed)
// yarn test:servers --keep unomi4 leave the server running afterwards
//
-// Not part of CI: it needs Docker and takes several minutes.
+// CI runs unomi3 and unomi4, one per job (.github/workflows/server-tests.yml).
const { spawnSync } = require('child_process');
const fs = require('fs');
const path = require('path');
diff --git a/test/servers/unomi.js b/test/servers/unomi.js
index 6a9d288..6f90255 100644
--- a/test/servers/unomi.js
+++ b/test/servers/unomi.js
@@ -105,6 +105,67 @@ async function retry(action, timeoutMs = 120000) {
}
}
+// Unomi 4 reports each of its parts in /health/check; returns true when all
are LIVE.
+async function healthy() {
+ const password = process.env.UNOMI_HEALTHCHECK_PASSWORD ||
'tracker-test-health';
+ const response = await fetch(UNOMI_URL + '/health/check', { headers: {
Authorization: basic('health:' + password) } });
+ if (!response.ok) {
+ return false;
+ }
+ const parts = await response.json();
+ return parts.length > 0 && parts.every(part => part.status === 'LIVE');
+}
+
+// The endpoints the tests use answer. A starting server registers its
endpoints one by one, and can
+// remove and add them again while it starts, so a single answer is not
enough. The event collector
+// refuses an empty list of events (400), which shows it is there without
storing anything.
+async function endpointsAnswer(publicKey, credentials) {
+ const probe = { sessionId: 'tracker-test-probe', events: [] };
+ const keyHeader = publicKey ? { 'X-Unomi-Api-Key': publicKey } : {};
+ const post = (path, body, headers) => fetch(UNOMI_URL + path, {
+ method: 'POST',
+ headers: Object.assign({ 'Content-Type': 'application/json' },
headers),
+ body: JSON.stringify(body)
+ });
+ const context = await post('/cxs/context.json', probe, keyHeader);
+ const collector = await post('/cxs/eventcollector', probe, keyHeader);
+ const search = await post('/cxs/events/search', { limit: 1 }, {
Authorization: basic(credentials) });
+ return context.status === 200 && (collector.status === 200 ||
collector.status === 400) && search.status === 200;
+}
+
+// Waits until all the parts of a Unomi 4 server are LIVE, before setting it
up. Earlier servers
+// have no health check here; the setup retries its calls on them.
+async function waitUntilHealthy(t, timeoutMs = 180000) {
+ if (t.major < 4) {
+ return;
+ }
+ await retry(async () => {
+ if (!await healthy()) {
+ throw new Error('Unomi is not LIVE yet at ' + UNOMI_URL);
+ }
+ }, timeoutMs);
+}
+
+// Waits until the server has kept answering for a while: STABLE_ROUNDS checks
in a row, 2s apart.
+const STABLE_ROUNDS = 5;
+async function waitUntilStable(t, publicKey, credentials, timeoutMs = 180000) {
+ const deadline = Date.now() + timeoutMs;
+ let rounds = 0;
+ while (rounds < STABLE_ROUNDS) {
+ let ok = false;
+ try {
+ ok = (t.major < 4 || await healthy()) && await
endpointsAnswer(publicKey, credentials);
+ } catch (e) {
+ // not answering yet
+ }
+ rounds = ok ? rounds + 1 : 0;
+ if (Date.now() > deadline) {
+ throw new Error('Unomi did not answer steadily at ' + UNOMI_URL +
' within ' + timeoutMs / 1000 + 's');
+ }
+ await sleep(2000);
+ }
+}
+
// The tenant a server stores the tracker data in: the test tenant on Unomi 4
multi-tenant,
// tenant "default" in compatibility mode, none on Unomi 2.x and 3.x.
function tenantOf(t) {
@@ -154,6 +215,7 @@ async function ensureScope(credentials) {
// credentials that can read the events.
async function setUp(t) {
await waitForServer();
+ await waitUntilHealthy(t);
const tenantId = tenantOf(t);
let publicKey;
let credentials = t.admin;
@@ -161,14 +223,16 @@ async function setUp(t) {
await ensureTenant(t, tenantId);
}
if (t.multiTenant) {
- // Keys can only be read when they are generated, so generate new ones
for this run
- const key = async type => (await request('POST', '/cxs/tenants/' +
tenantId + '/apikeys?type=' + type, { credentials: t.admin })).plainTextKey;
+ // Keys can only be read when they are generated, so generate new ones
for this run. The
+ // endpoint can still be missing (404) just after the tenant is
created.
+ const key = type => retry(async () => (await request('POST',
'/cxs/tenants/' + tenantId + '/apikeys?type=' + type, { credentials: t.admin
})).plainTextKey);
publicKey = await key('PUBLIC');
credentials = tenantId + ':' + await key('PRIVATE');
console.log('Tenant ' + tenantId + ' public key: ' + publicKey);
}
// In compatibility mode, administrator requests work on tenant "default"
await ensureScope(credentials);
+ await waitUntilStable(t, publicKey, credentials);
console.log('Server ready: ' + t.name + (tenantId ? ', tenant ' + tenantId
: '') + ', scope ' + SCOPE);
return { publicKey: publicKey, credentials: credentials };
}