bito-code-review[bot] commented on code in PR #43004:
URL: https://github.com/apache/superset/pull/43004#discussion_r4047838449


##########
superset-frontend/playwright/tests/dashboard/global-async-query.spec.ts:
##########
@@ -0,0 +1,419 @@
+/**
+ * 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.
+ *
+ * Requires the `GLOBAL_ASYNC_QUERIES` feature flag, Redis, and a running
+ * Celery worker -- without a worker, submissions still return 202 but no job
+ * ever executes and these tests time out. The cache-hit test is the exception:
+ * it is served synchronously and needs only the flag.
+ */
+import { testWithAssets, expect } from '../../helpers/fixtures';
+import { apiPostVirtualDataset } from '../../helpers/api/dataset';
+import { getDatabaseByName } from '../../helpers/api/database';
+import { extractIdFromResponse } from '../../helpers/api/assertions';
+import { TIMEOUT } from '../../utils/constants';
+import {
+  BIG_NUMBER_COUNT_SPEC,
+  bigNumberValueLocator,
+  createDashboardWithCharts,
+  setupDashboardWithBigNumberCharts,
+  setupDashboardWithSelectFilter,
+  trackGaqSignals,
+} from './dashboard-test-helpers';
+import { DashboardPage } from '../../pages/DashboardPage';
+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(
+  'forced dashboard refresh goes through the GAQ 202 -> poll -> done cycle',
+  async ({ page, testAssets }) => {
+    const { dashboard, charts, valueLocators } =
+      await setupDashboardWithBigNumberCharts(
+        page,
+        testAssets,
+        testWithAssets.info(),
+        {
+          datasetName: 'birth_names',
+          chartNamePrefix: 'gaq_tc1_cold_cache',
+          chartSpecs: [BIG_NUMBER_COUNT_SPEC],
+        },
+      );
+    const [chart] = charts;
+    const [value] = valueLocators;
+    await expect(value).toBeVisible({ timeout: TIMEOUT.CHART_RENDER });
+
+    // Track only after the initial load settles, so these signals describe the
+    // forced refresh rather than the load that preceded it.
+    const signals = trackGaqSignals(page);
+
+    // A fresh chart's query can still collide with an identical one another
+    // suite already cached, so force the refresh: forced requests take the
+    // async path regardless of cache state.
+    await dashboard.forceRefresh();
+    await expect(value).toBeVisible({ timeout: TIMEOUT.CHART_RENDER });
+    await expect(value).toHaveText(/\d/);
+
+    await expect(() => {
+      expect(
+        signals.submitStatusFor(chart.id),
+        'forced chart-data submission should be accepted (202) onto the async 
path',
+      ).toBe(202);
+      expect(
+        signals.sawTaskStatusPoll,
+        'the client should have polled /api/v1/task/status_changes while the 
tasks ran',
+      ).toBe(true);
+      expect(
+        signals.submitStatusesFor(chart.id),
+        'the client should re-issue chart-data once the tasks finish and be 
served 200 from the warmed cache',
+      ).toEqual([202, 200]);
+    }).toPass({ timeout: TIMEOUT.CHART_RENDER });
+  },
+);
+
+testWithAssets(
+  'a cold first load resolves through the GAQ cycle with no manual refresh',
+  async ({ page, testAssets }) => {
+    testWithAssets.setTimeout(TIMEOUT.SLOW_TEST);
+
+    const examplesDb = await getDatabaseByName(page, 'examples');
+    if (!examplesDb) {
+      throw new Error('examples database not found');
+    }
+
+    // The test above forces a refresh, because a fresh chart over a shared
+    // physical table can collide with a query another suite already cached and
+    // a forced request takes the async path regardless of cache state. That
+    // leaves the unforced first load -- the one a real user gets -- 
unasserted.
+    //
+    // Same fix as the native-filter test below: a per-run SQL comment keeps 
the
+    // query text, and so its cache key, unique. This load is therefore
+    // guaranteed cold, and the async cycle can be asserted on the initial
+    // render itself rather than on a refresh that follows it.
+    const uniqueSuffix = 
`${Date.now()}_${testWithAssets.info().parallelIndex}`;
+    const datasetResp = await apiPostVirtualDataset(page, {
+      database: examplesDb.id,
+      schema: '',
+      table_name: `gaq_cold_first_load_${uniqueSuffix}`,
+      sql: `SELECT name FROM birth_names /* run:${uniqueSuffix} */`,
+      editors: [],
+    });
+    expect(datasetResp.ok()).toBe(true);
+    const datasetId = await extractIdFromResponse(datasetResp);
+    testAssets.trackDataset(datasetId);

Review Comment:
   <!-- Bito Reply -->
   The refactoring of the dataset setup into a shared helper is a positive 
improvement. It eliminates code duplication, ensures consistent behavior across 
tests, and simplifies the test suite by removing the need for manual 
synchronization comments.



-- 
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