mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
FerretDB v1 translates one MongoDB query into five different SQL dialects, so
"WeKan starts on MariaDB" says very little. The question that decides whether a
backend can be trusted with a board is whether {n: {$gt: 5}} returns the same
documents, in the same order, as it does on SQLite - and nothing was asking it.
./build.sh -> Tests -> "All databases (sequential)" now does, and build.bat has
the same entry (running the same script through bash rather than a second
implementation that would drift).
It builds FerretDB v1 from source first: the FerretDB subdirectory is cloned
from git@github.com:wekan/FerretDB if it is not there, updated if it is, and
built through its own build.sh, which installs the Go toolchain and the module
dependencies when they are missing. The tests run against THAT binary, not a
downloaded release, so they test the newest code.
Then, for each backend whose database image has a build for THIS CPU - asked of
the registry with docker manifest inspect, so no table here can go stale - it
starts that database, runs the freshly built FerretDB against it, runs the whole
catalogue and stops everything. Sequential, because they all use the same
FerretDB port and a database under test should not be competing with three
others; the menu entry says so.
The catalogue is 100 cases in 15 groups, taken from FerretDB v1's own handler
sources rather than from MongoDB's manual: every query, update and bitwise
operator, the aggregation stages and accumulators, projection and sorting and
paging, count and distinct, indexes and uniqueness, capped collections (which is
how the OpLog exists at all), and the commands whose answers may legitimately
differ. The seed data is deliberately awkward - a null, a missing field, a
negative number, a zero, an empty array, an array of documents - because tidy
data lets a broken translation pass.
Answers are normalised and compared byte for byte against SQLite, so document
ORDER counts. Three cases are compared loosely and say so: an explain plan
differs per engine by definition, and collStats/dbStats are sizes a different
storage engine may answer differently. Two backends failing the same way is
agreement about a limitation; one answering where another fails is a difference.
Everything lands in ../log/<datetime>/ with every other test run: a JSON of what
each backend answered, each backend's container output, the build log, a summary
and db-conformance-report.md. SAP HANA is opt-in behind WEKAN_CONFORMANCE_HANA=1
- amd64-only, ~16 GB of RAM, and SAP's licence to accept - so a menu choice
cannot start it by accident.
Thanks to xet7 !
161 lines
6.4 KiB
JavaScript
161 lines
6.4 KiB
JavaScript
'use strict';
|
|
|
|
// Did every database answer the same?
|
|
//
|
|
// node tests/dbConformance/compare.cjs --dir ../log/2026-07-28_12-00-00 \
|
|
// [--reference sqlite]
|
|
//
|
|
// Reads every db-conformance-<label>.json in <dir>, compares each case against
|
|
// the reference backend, and writes db-conformance-report.md beside them. Exits
|
|
// non-zero when a backend disagrees with the reference on a case that is supposed
|
|
// to be identical - which is the whole point of running this.
|
|
//
|
|
// The comparison itself is a pure function (compareRuns), so it is unit-tested
|
|
// without a database: tests/dbConformanceWiring.test.cjs.
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// ── the pure part ───────────────────────────────────────────────────────────
|
|
|
|
// Deep equality on the already-normalised values run.cjs wrote.
|
|
function same(a, b) {
|
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
}
|
|
|
|
// Compare every run against the reference run.
|
|
//
|
|
// Returns { reference, labels, cases: [{id, group, name, compare, verdict,
|
|
// perLabel: {label: 'same'|'different'|'error'|'missing'}}], summary }
|
|
//
|
|
// verdict is:
|
|
// 'agree' - every backend gave the same answer (or all agreed it errors)
|
|
// 'differ' - at least one backend's answer differs from the reference
|
|
// 'error' - at least one backend could not answer at all
|
|
// A case whose `compare` is 'ok' only has to have been answered.
|
|
function compareRuns(runs, referenceLabel) {
|
|
const byLabel = new Map(runs.map(r => [r.label, r]));
|
|
const reference = byLabel.has(referenceLabel) ? referenceLabel : runs[0] && runs[0].label;
|
|
const ref = byLabel.get(reference);
|
|
if (!ref) return { reference: null, labels: [], cases: [], summary: { agree: 0, differ: 0, error: 0 } };
|
|
|
|
const labels = runs.map(r => r.label);
|
|
const cases = [];
|
|
const summary = { agree: 0, differ: 0, error: 0 };
|
|
|
|
for (const refCase of ref.results) {
|
|
const perLabel = {};
|
|
let differ = false;
|
|
let error = 'error' in refCase;
|
|
|
|
for (const label of labels) {
|
|
const run = byLabel.get(label);
|
|
const mine = (run.results || []).find(x => x.id === refCase.id);
|
|
if (!mine) { perLabel[label] = 'missing'; differ = true; continue; }
|
|
if ('error' in mine) {
|
|
// Two backends failing the SAME way is agreement about a limitation,
|
|
// which is worth knowing and is not a difference between them.
|
|
perLabel[label] = ('error' in refCase && mine.error === refCase.error) ? 'same-error' : 'error';
|
|
if (perLabel[label] === 'error') error = true;
|
|
continue;
|
|
}
|
|
if ('error' in refCase) { perLabel[label] = 'answered'; differ = true; continue; }
|
|
if (refCase.compare === 'ok') { perLabel[label] = 'answered'; continue; }
|
|
perLabel[label] = same(mine.value, refCase.value) ? 'same' : 'different';
|
|
if (perLabel[label] === 'different') differ = true;
|
|
}
|
|
|
|
const verdict = differ ? 'differ' : (error ? 'error' : 'agree');
|
|
summary[verdict] += 1;
|
|
cases.push({ id: refCase.id, group: refCase.group, name: refCase.name,
|
|
compare: refCase.compare, verdict, perLabel });
|
|
}
|
|
|
|
return { reference, labels, cases, summary };
|
|
}
|
|
|
|
// The report, as text. Pure, so the test can read it.
|
|
function renderReport(cmp, meta = {}) {
|
|
const lines = [];
|
|
lines.push('# FerretDB v1: do all backends answer the same?');
|
|
lines.push('');
|
|
if (meta.when) lines.push(`Run: ${meta.when}`);
|
|
if (meta.platform) lines.push(`Platform: ${meta.platform}`);
|
|
lines.push(`Reference backend: **${cmp.reference}**`);
|
|
lines.push(`Backends compared: ${cmp.labels.join(', ')}`);
|
|
lines.push('');
|
|
lines.push(`| Verdict | Cases |`);
|
|
lines.push(`| --- | --- |`);
|
|
lines.push(`| Same answer everywhere | ${cmp.summary.agree} |`);
|
|
lines.push(`| **Different** | ${cmp.summary.differ} |`);
|
|
lines.push(`| Errored somewhere | ${cmp.summary.error} |`);
|
|
lines.push('');
|
|
|
|
const bad = cmp.cases.filter(c => c.verdict !== 'agree');
|
|
if (!bad.length) {
|
|
lines.push('Every backend answered every case the same way.');
|
|
} else {
|
|
lines.push('## Where they disagree');
|
|
lines.push('');
|
|
lines.push(`| Case | ${cmp.labels.join(' | ')} |`);
|
|
lines.push(`| --- | ${cmp.labels.map(() => '---').join(' | ')} |`);
|
|
for (const c of bad) {
|
|
lines.push(`| ${c.id} | ${cmp.labels.map(l => c.perLabel[l] || '-').join(' | ')} |`);
|
|
}
|
|
lines.push('');
|
|
lines.push('`different` = answered, but not the same as the reference. `error` = ' +
|
|
'could not answer. `same-error` = failed the same way as the reference, which ' +
|
|
'is agreement about a limitation rather than a difference.');
|
|
}
|
|
lines.push('');
|
|
lines.push('## Every case');
|
|
lines.push('');
|
|
let group = null;
|
|
for (const c of cmp.cases) {
|
|
if (c.group !== group) { group = c.group; lines.push(`### ${group}`); lines.push(''); }
|
|
const mark = c.verdict === 'agree' ? 'same' : c.verdict;
|
|
lines.push(`- ${mark === 'same' ? 'OK ' : mark.toUpperCase()} ${c.name}`);
|
|
}
|
|
lines.push('');
|
|
return lines.join('\n');
|
|
}
|
|
|
|
module.exports = { compareRuns, renderReport, same };
|
|
|
|
// ── the script part ─────────────────────────────────────────────────────────
|
|
if (require.main === module) {
|
|
const arg = (name, fallback) => {
|
|
const i = process.argv.indexOf(`--${name}`);
|
|
return i !== -1 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
|
|
};
|
|
const dir = arg('dir', '.');
|
|
const reference = arg('reference', 'sqlite');
|
|
|
|
const runs = fs.readdirSync(dir)
|
|
.filter(f => /^db-conformance-.*\.json$/.test(f))
|
|
.map(f => JSON.parse(fs.readFileSync(path.join(dir, f), 'utf8')))
|
|
.sort((a, b) => a.label.localeCompare(b.label));
|
|
|
|
if (!runs.length) {
|
|
console.error(`No db-conformance-*.json in ${dir} - nothing to compare.`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const cmp = compareRuns(runs, reference);
|
|
const report = renderReport(cmp, {
|
|
when: new Date().toISOString(),
|
|
platform: `${process.platform}/${process.arch}`,
|
|
});
|
|
const out = path.join(dir, 'db-conformance-report.md');
|
|
fs.writeFileSync(out, report);
|
|
|
|
console.log(report.split('\n## Every case')[0]);
|
|
console.log(`Full report: ${out}`);
|
|
|
|
if (runs.length === 1) {
|
|
console.log('Only one backend ran, so there was nothing to compare it with.');
|
|
process.exit(0);
|
|
}
|
|
process.exit(cmp.summary.differ > 0 ? 1 : 0);
|
|
}
|