drivaspreset commented on code in PR #43004:
URL: https://github.com/apache/superset/pull/43004#discussion_r4135007093


##########
superset-frontend/playwright/tests/dashboard/global-async-query-resilience.spec.ts:
##########
@@ -0,0 +1,366 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Global Async Queries (GAQ) under stress: a query that fails, a superseded
+ * query racing a newer one, a lost channel token, and a page torn down
+ * mid-flight.
+ *
+ * GAQ's happy path is visually identical to a synchronous load, so these are
+ * the cases where its machinery actually becomes observable -- or where it
+ * must stay invisible. The happy paths live in global-async-query.spec.ts.
+ *
+ * Requires the `GLOBAL_ASYNC_QUERIES` feature flag, Redis, and a running
+ * Celery worker.
+ */
+import { testWithAssets, expect } from '../../helpers/fixtures';
+import { apiGetChart, apiPutChart } from '../../helpers/api/chart';
+import { TIMEOUT } from '../../utils/constants';
+import { apiPost } from '../../helpers/api/requests';
+import {
+  BIG_NUMBER_COUNT_SPEC,
+  setupDashboardWithBigNumberCharts,
+  setupDashboardWithSelectFilter,
+  sliceIdFromChartDataUrl,
+  trackGaqSignals,
+} from './dashboard-test-helpers';
+import { isFeatureEnabled } from '../../helpers/featureFlags';
+
+testWithAssets.beforeEach(async ({ page }) => {
+  await page.goto('chart/list/');
+  testWithAssets.skip(
+    !(await isFeatureEnabled(page, 'GLOBAL_ASYNC_QUERIES')),
+    'GLOBAL_ASYNC_QUERIES is not enabled on this instance',
+  );
+});
+
+testWithAssets(
+  'broken chart surfaces a clean error under GAQ instead of hanging, and 
recovers once fixed',
+  async ({ page, testAssets }) => {
+    // Two forced refreshes plus an API round-trip between them exceed the
+    // default timeout on a loaded runner.
+    testWithAssets.setTimeout(TIMEOUT.SLOW_TEST);
+
+    const BAD_COLUMN = 'this_column_does_not_exist_gaq_test';
+
+    // A custom SQL metric on a nonexistent column fails in Postgres, not in
+    // client-side validation -- so the job really is queued and run, and this
+    // exercises the async error path rather than a request that never ships.
+    const { dashboardId, dashboard, charts, valueLocators } =
+      await setupDashboardWithBigNumberCharts(
+        page,
+        testAssets,
+        testWithAssets.info(),
+        {
+          datasetName: 'birth_names',
+          chartNamePrefix: 'gaq_tc3_broken_chart',
+          chartSpecs: [
+            {
+              viz_type: 'big_number_total',
+              params: {
+                metric: {
+                  expressionType: 'SQL',
+                  sqlExpression: `SUM(${BAD_COLUMN})`,
+                  label: 'broken_metric',
+                  hasCustomLabel: true,
+                },
+              },
+            },
+          ],
+        },
+      );
+    const [chart] = charts;
+    const [value] = valueLocators;
+    const errorAlert = 
dashboard.getChart(chart.id).locator('.ant-alert-error');
+
+    // Let the initial (also broken) load settle before tracking.
+    await expect(errorAlert).toBeVisible({ timeout: TIMEOUT.CHART_RENDER });
+
+    const signals = trackGaqSignals(page);
+
+    await dashboard.forceRefresh();
+
+    await expect(errorAlert).toBeVisible({ timeout: TIMEOUT.CHART_RENDER });
+    await expect(errorAlert).toContainText('Data error');
+    await expect(errorAlert).toContainText(BAD_COLUMN);
+
+    await expect(() => {
+      expect(
+        signals.submitStatusFor(chart.id),
+        'forced chart-data submission for the broken chart should still be 
accepted (202) onto the async path',
+      ).toBe(202);
+      expect(
+        signals.sawTaskStatusPoll,
+        'the client should have polled /api/v1/task/status_changes while the 
broken query ran',
+      ).toBe(true);
+    }).toPass({ timeout: TIMEOUT.CHART_RENDER });
+
+    // Fix the config and confirm the chart recovers, rather than staying 
stuck.
+    const chartResp = await apiGetChart(page, chart.id);
+    expect(chartResp.ok()).toBe(true);
+    const { result } = await chartResp.json();
+    const fixedParams = { ...JSON.parse(result.params), metric: 'count' };
+
+    const updateResp = await apiPutChart(page, chart.id, {
+      params: JSON.stringify(fixedParams),
+    });
+    expect(updateResp.ok()).toBe(true);
+
+    // Refreshing re-submits the form_data already loaded client-side, so it
+    // would not pick up an out-of-band config change. Re-navigating refetches
+    // the chart's metadata.
+    await dashboard.gotoById(dashboardId);
+    await dashboard.waitForLoad();
+
+    await expect(value).toBeVisible({ timeout: TIMEOUT.CHART_RENDER });
+    await expect(value).toHaveText(/\d/);
+    await expect(errorAlert).not.toBeAttached();
+  },
+);
+
+testWithAssets(
+  'rapidly switching a filter value never lets the superseded selection 
clobber the screen',
+  async ({ page, testAssets }) => {
+    testWithAssets.setTimeout(TIMEOUT.SLOW_TEST);
+
+    const RACE_DELAY_MS = 3000;
+
+    const { chartId, dashboardId, dashboard, filterBar, value } =
+      await setupDashboardWithSelectFilter(
+        page,
+        testAssets,
+        testWithAssets.info(),
+        {
+          datasetName: 'birth_names',
+          namePrefix: 'gaq_tc4_filter_race',
+          filterColumn: 'gender',
+          filterName: 'Gender',
+        },
+      );
+
+    await dashboard.gotoById(dashboardId);
+    await dashboard.waitForLoad({ timeout: TIMEOUT.SLOW_TEST });
+    await expect(value).toBeVisible({ timeout: TIMEOUT.CHART_RENDER });
+
+    // Learn "girl"'s real count first, so the race can assert on that specific
+    // number. The unfiltered total already contains a digit, so a bare /\d/
+    // would pass even if the request never completed.
+    await filterBar.selectOption('girl');
+    await filterBar.apply();
+    await expect(value).toHaveText(/\d/, { timeout: TIMEOUT.CHART_RENDER });
+    const expectedGirlText = await value.textContent();

Review Comment:
   Correct — and it's the same trap the later part of this test already 
documents: the chart keeps displaying the previous value while a query is in 
flight, so `toHaveText(/\d/)` is satisfied by the *unfiltered* total and the 
baseline silently becomes wrong whenever girl's query is slow.
   
   Fixed in d56f007ffc by gating the baseline on the network, the way the race 
assertion below it already does:
   
   ```ts
   const baselineSignals = trackGaqSignals(page);
   await filterBar.selectOption('girl');
   await filterBar.apply();
   await expect(() => {
     const statuses = baselineSignals.submitStatusesFor(chartId);
     expect(statuses).not.toHaveLength(0);
     expect(statuses.every(s => s === 200 || s === 202)).toBe(true);
     expect(statuses[statuses.length - 1]).toBe(200);
   }).toPass({ timeout: TIMEOUT.CHART_RENDER });
   ```
   
   Ending on a 200 covers both legitimate shapes — a straight cache hit, or 
`202` then `200` — while rejecting a 4xx/5xx that would otherwise leave stale 
pixels on screen for the text read to pick up. Only then is `expectedGirlText` 
captured.
   
   Passing on the current run (test 2, both legs).



##########
superset-frontend/playwright/tests/dashboard/global-async-query.spec.ts:
##########
@@ -0,0 +1,394 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Global Async Queries (GAQ): the pipeline works for each of its consumers --
+ * a cold first load, a forced refresh, the cache-hit shortcut that bypasses 
the
+ * cycle entirely, many charts at once, and native filter value lookups.
+ *
+ * Failure and edge-case behavior lives in 
global-async-query-resilience.spec.ts.
+ * SQL Lab's smoke check lives in tests/sqllab/, which needs the
+ * `chromium-sqllab` project rather than this directory's default one.

Review Comment:
   You're right — the comment said the opposite of what the config does. Fixed 
in d56f007ffc:
   
   ```
    * SQL Lab's smoke check lives in tests/sqllab/ but runs under the same
    * `chromium-gaq` project as these specs -- `chromium-sqllab` deliberately
    * excludes it via `testIgnore`, since it needs the flag only the GAQ job 
sets.
   ```
   
   I also updated the header of `global-async-query-sqllab.spec.ts` itself, 
which described how that project gets selected in terms that predated the 
switch to `--project=chromium-gaq`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to