Repository navigation
tests: Unflake and fix dataflow visualizer - #38359
Conversation
dd216ef to
40d09b9
Compare
antiguru
left a comment
There was a problem hiding this comment.
The direction is right: pinning the tests to a fixture dataflow instead of "whatever sorts first" removes a real source of flakiness, and dropping the test.skip-on-DDL-failure dance in favour of setting the fixture up over pgwire is a clear improvement. The comments explaining why each choice is load-bearing are genuinely useful.
One blocker plus a few things worth folding in before merge. Inline comments have the detail; summarising here.
Blocker
test/dataflow-visualizer/tests/fixture.ts is missing from the branch. Both spec files import FIXTURE_CLUSTER/FIXTURE_REPLICA/FIXTURE_INDEX/FIXTURE_DATAFLOW/fixturePage from ./fixture, so as it stands Playwright can't load either file. Details inline on memory.spec.ts.
Should fix
- Step timeout headroom.
workers: 1plus a 3x per-test timeout, againsttimeout_in_minutes: 30. Inline onplaywright.config.ts. - The step doesn't run on visualizer changes.
inputs: [test/dataflow-visualizer](ci/test/pipeline.template.yml:835) doesn't coversrc/environmentd/src/http/static/js. This PR changes production JSX that the new tests now assert on, but a future JSX-only change skips the suite entirely, which undercuts the coverage being built here. Adding the static js directory toinputswould make it load-bearing. create_fixture_dataflowis no longer idempotent. Inline onmzcompose.py.
Worth considering
ClusterReplicaViewis now duplicated verbatim acrossmemory.jsxandhierarchical-memory.jsx, new comment block and all. There's already a sharedfetch.js; hoisting this into a sharedcluster-replica.jsxwould stop the copy growing. Happy for this to be a follow-up.hierarchical-memory.spec.ts'spage renders without crashing after data loadstill doeswaitForTimeout(3000)thennot.toContainText('error:'), which passes vacuously while the page is still showingLoading.... Same class of weakness as the ones fixed inmemory.spec.ts, and now that the page defaults toquickstartit's cheap to wait for the real render instead.- The "dataflows reporting none sort first" comment (both
mzcompose.pyandmemory.spec.ts) is correct, but only becauserecordsis nullable inmz_records_per_dataflowandORDER BY records DESCis NULLS FIRST. "Reporting none" reads like zero, which would sort last. Naming the NULL would make the comment stand on its own. const [session_cluster_table, replicas_table] = data.results;followed bysessionClustermixes conventions within three lines.Viewsusesrecords_table, so snake_case is locally consistent; it's just the mix that reads oddly.with c.sql_cursor(...)closes the cursor but leaks the connection, sincereuse_connectiondefaults toFalse.
Pre-existing bug, for a follow-up
Noticed while reading hierarchical-memory.jsx. getCreateView(stats.name) (line 178) reads stats, which is useState(null) and never assigned, so it always throws a TypeError that the surrounding try/catch swallows into a console.debug. And getCreateView itself reads view_name_table.rows and create_table.rows[0][0], but query() returns {results: [...]} — so the SHOW CREATE VIEW panel on that page has never worked. Out of scope for an unflaking PR, but it's the largest actual defect in a file this one is titled as fixing, so it seemed worth recording.
Generated by Claude Code
| import { | ||
| FIXTURE_CLUSTER, | ||
| FIXTURE_DATAFLOW, | ||
| FIXTURE_REPLICA, | ||
| fixturePage, | ||
| } from './fixture'; |
There was a problem hiding this comment.
Blocker: tests/fixture.ts isn't in the branch. Listing test/dataflow-visualizer/tests/ at dd216ef gives only the four *.spec.ts files, and the diff's six changed files are all accounted for elsewhere. So both this file and hierarchical-memory.spec.ts fail module resolution and all 12 of their tests error out instead of running.
Worth noting it won't be caught before the mzcompose step either: ci/test/lint-main/checks/check-js-typedefs.sh typechecks only the three files listed in tsconfig.typecheck.json (prometheus.js, metrics.jsx, fetch.js), not the specs.
Two things to watch when adding it:
FIXTURE_DATAFLOWhas no counterpart in the serviceenvironmentlist inmzcompose.py(onlyFIXTURE_CLUSTER,FIXTURE_REPLICA,FIXTURE_INDEXare passed), so it has to be derived, and the derivation needs theDataflow: materialize.public.prefix from somewhere.- A fallback for the env vars would keep
npx playwright testusable outside the composition.
Generated by Claude Code
| // behind the visualizer are unindexed scans. Two workers on a CI agent turn | ||
| // those into multi-second waits that trip the assertion timeouts below, so | ||
| // pin the suite to a single worker rather than only serializing each file. | ||
| fullyParallel: false, | ||
| workers: 1, | ||
| retries: 1, |
There was a problem hiding this comment.
workers: 1 plus the per-test timeout going 30s to 90s, across ~34 tests with retries: 1, runs against timeout_in_minutes: 30 on the Buildkite step (ci/test/pipeline.template.yml:834). Before this, fullyParallel: false still let the four spec files run concurrently, so on the 4cpu agent the suite was effectively 4-way parallel; serializing it multiplies wall clock at the same time as the timeout budget per test triples.
A step timeout is exactly the opaque failure this PR is trying to remove, so it'd be worth raising timeout_in_minutes in the same commit.
Separately, LOAD_TIMEOUT in memory.spec.ts is doing what a config-level expect: { timeout: ... } would do for the whole suite. hierarchical-memory.spec.ts still hardcodes its own 20000s in three places.
Generated by Claude Code
| c.sql(f""" | ||
| CREATE TABLE {FIXTURE_TABLE} (id int, other int); | ||
| CREATE INDEX {FIXTURE_INDEX} IN CLUSTER {FIXTURE_CLUSTER} ON {FIXTURE_TABLE} (id); | ||
| INSERT INTO {FIXTURE_TABLE} VALUES (1, 1); |
There was a problem hiding this comment.
The DDL this replaces used IF NOT EXISTS, and dropping that makes the workflow non-idempotent: re-running it against an already-up composition (without down -v) now fails on "table already exists" before any test runs. Cheap to restore, and then the INSERT just adds a second row, which none of the assertions care about.
Generated by Claude Code
| // The first statement decides which replica to show when the URL names none. | ||
| // Ask the session for its cluster rather than naming one here: the built-in | ||
| // default has been renamed before, and a name hardcoded in this file that | ||
| // stops matching fails silently, leaving the page on whichever replica | ||
| // happens to sort first. | ||
| const queryClusterReplicas = ` | ||
| SELECT current_setting('cluster'); |
There was a problem hiding this comment.
Design question rather than a bug. In a real deployment the internal port is reached through a proxy that injects x-materialize-user: mz_support (src/environmentd/src/http.rs:781), and mz_support's default cluster is mz_catalog_server (INTERNAL_USER_NAME_TO_DEFAULT_CLUSTER, src/sql/src/session/user.rs:52). So for the users who actually open this page, current_setting('cluster') resolves to exactly the expensive builtin cluster the new comment describes as "not what a user opening this page came to look at". Under test the user is anonymous_http_user, whose cluster is the system default quickstart, which is why the new assertion passes.
Not a regression: the old default/r1 preference never matched a modern bootstrap, so it already fell through to results[0], which is mz_catalog_server under ORDER BY cluster_name. But the stated benefit only materializes for anonymous sessions. If the intent is "prefer a user cluster", it might be worth encoding that directly: session cluster, then first non-system cluster, then first replica.
Two things I checked so you don't have to:
- The two-statement simple request is safe.
current_settingplans throughUnmaterializableFunc::ViewableVariablesand folds to a constant, so the first statement pins no timestamp,timedomain_forgets an empty id set, and no read holds are stored. The second statement is then free to establish the timedomain, so noRelationOutsideTimeDomain.Viewsbelow already relies on multi-statement requests anyway. - The new test's
#cluster_replicaassertion does discriminate, sincequickstartsorts after everymz_*cluster.
Minor: "Rows are ordered by replica name" undersells it. The query orders by cluster_name ASC, replica_name ASC, and it's the cluster ordering that decides what results[0] is.
Generated by Claude Code
40d09b9 to
a619221
Compare
|
Thanks for the review, fixed up, except for the sleep timeout (already way below the 30 min) and |
antiguru
left a comment
There was a problem hiding this comment.
All addressed, thanks. Extracting the picker into cluster-replica.jsx and preferring a user cluster over the session's own is a better answer than what I suggested, and fixing getCreateView for real (plus indexing a view so the lookup resolves, plus a test for it) turns the pre-existing dead panel into working code. Widening tsconfig.typecheck.json to the specs is the part that keeps this from regressing.
Verified locally: npm install --prefix test/dataflow-visualizer && tsc -p test/dataflow-visualizer/tsconfig.typecheck.json is clean, and the new cluster-replica.jsx needs no registration since handle_static uses include_dir! over the whole directory.
One nit, take it or leave it: replicaPage in tests/fixture.ts is exported but only called by fixturePage two lines below it.
Generated by Claude Code
QA LLM Review (Post Merge)@def- — an automated review of commit 1. HIGH -- Fixing
|
The /memory page resolves an expanded dataflow back to the view its index was built on, and interpolated both the index name it parses out of the dataflow name and the view name that lookup returns straight into the statements it sends to /api/sql. Those names are chosen by whoever created the object, and the statements run in the session of whoever opened the page, so a catalog name carrying a quote could run SQL with the viewer's privileges. The escaper the pages already had for cluster and replica names passed a string rather than a regex to String.replace, so it escaped only the first quote of a name, which is no escaping at all for a name carrying two. Those two names come straight from URL parameters, as does the dataflow id, which is interpolated as a number and so cannot be made safe by quoting at all, and is now rejected unless it is an integer. Both pages now quote through sqlLiteral and sqlIdent in fetch.js, which they already share for the /api/sql call itself, and a browser test pins that both helpers escape every quote rather than just the first. Found via the QA LLM review, sorry for only catching it after the PR merged: #38359 (comment) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Keeps failing in CI, see for example https://buildkite.com/materialize/test/builds/131939#01a01a66-ff4c-43bd-a5b4-f53b0d57c626