Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ import {
createCustomMetric,
deleteCustomMetric,
} from '../../utils/customMetric';
import {
forceFreshTableReads,
waitForAllLoadersToDisappear,
} from '../../utils/entity';
import { waitForAllLoadersToDisappear } from '../../utils/entity';

// use the admin user to login
test.use({ storageState: 'playwright/.auth/admin.json' });

test('Table custom metric', async ({ page }) => {
const table = new TableClass();
await redirectToHomePage(page);
await forceFreshTableReads(page);
const { afterAction, apiContext } = await getApiContext(page);
await table.create(apiContext);

Expand Down Expand Up @@ -70,7 +66,6 @@ test('Table custom metric', async ({ page }) => {
test('Column custom metric', async ({ page }) => {
const table = new TableClass();
await redirectToHomePage(page);
await forceFreshTableReads(page);
const { afterAction, apiContext } = await getApiContext(page);
await table.create(apiContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import {
ObservabilityFeature,
selectAddObservabilityFeature,
} from '../../utils/dataQuality';
import {
forceFreshTableReads,
waitForAllLoadersToDisappear,
} from '../../utils/entity';
import { waitForAllLoadersToDisappear } from '../../utils/entity';
import {
confirmIngestionPipelineHardDelete,
submitTestCaseForm,
Expand All @@ -43,7 +40,6 @@ test(
test.slow(true);

await redirectToHomePage(page);
await forceFreshTableReads(page);
const { apiContext, afterAction } = await getApiContext(page);
const table = new TableClass(`multi pipeline !@#$%^&*()_-+=test-${uuid()}`);
await table.create(apiContext);
Expand Down Expand Up @@ -246,7 +242,6 @@ test(
test.slow(true);

await redirectToHomePage(page);
await forceFreshTableReads(page);
const { apiContext, afterAction } = await getApiContext(page);
const table = new TableClass(`multi pipeline !@#$%^&*()_-+=test-${uuid()}`);
await table.create(apiContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test as setup } from '@playwright/test';
import { Page, test as setup } from '@playwright/test';
import { DISABLE_ETAG_CONDITIONAL_READS_KEY } from '../../src/rest/etagInterceptor';
import {
EDIT_DESCRIPTION_RULE,
EDIT_GLOSSARY_TERM_RULE,
Expand All @@ -22,6 +23,21 @@ import { UserClass } from '../support/user/UserClass';
import { getApiContext, uuid } from '../utils/common';
import { loginAsAdmin } from '../utils/initialSetup';

/**
* Opt every E2E session out of client-side conditional (If-None-Match) reads.
*
* The server ETag only covers the entity's version/updatedAt, so it does not change for
* relationship-only or child mutations (followers, votes, customMetrics, testSuite). A refetch
* racing such a mutation can be answered "not modified" and render a stale body, which surfaces
* as flaky assertions across the suite. Setting the flag here persists it into storageState, so
* every spec in both OpenMetadata and Collate inherits it without a per-test helper.
*/
const disableEtagConditionalReads = async (page: Page) => {
await page.evaluate((key) => {
localStorage.setItem(key, 'true');
}, DISABLE_ETAG_CONDITIONAL_READS_KEY);
};

const adminFile = 'playwright/.auth/admin.json';
const dataConsumerFile = 'playwright/.auth/dataConsumer.json';
const dataStewardFile = 'playwright/.auth/dataSteward.json';
Expand Down Expand Up @@ -208,42 +224,50 @@ setup('authenticate all users', async ({ browser }) => {
await adminPage.waitForTimeout(2000);

// Save admin state
await disableEtagConditionalReads(newAdminPage);
await newAdminPage
.context()
.storageState({ path: adminFile, indexedDB: true });

// Save states for each user sequentially to avoid file operation conflicts
await dataConsumer.login(dataConsumerPage);
await disableEtagConditionalReads(dataConsumerPage);
await dataConsumerPage
.context()
.storageState({ path: dataConsumerFile, indexedDB: true });

await dataSteward.login(dataStewardPage);
await disableEtagConditionalReads(dataStewardPage);
await dataStewardPage
.context()
.storageState({ path: dataStewardFile, indexedDB: true });

await editDescriptionUser.login(editDescriptionPage);
await disableEtagConditionalReads(editDescriptionPage);
await editDescriptionPage
.context()
.storageState({ path: editDescriptionFile, indexedDB: true });

await editTagsUser.login(editTagsPage);
await disableEtagConditionalReads(editTagsPage);
await editTagsPage
.context()
.storageState({ path: editTagsFile, indexedDB: true });

await editGlossaryTermUser.login(editGlossaryTermPage);
await disableEtagConditionalReads(editGlossaryTermPage);
await editGlossaryTermPage
.context()
.storageState({ path: editGlossaryTermFile, indexedDB: true });

await viewOnlyUser.login(viewOnlyPage);
await disableEtagConditionalReads(viewOnlyPage);
await viewOnlyPage
.context()
.storageState({ path: viewOnlyFile, indexedDB: true });

await ownerUser.login(ownerPage);
await disableEtagConditionalReads(ownerPage);
await ownerPage
.context()
.storageState({ path: ownerFile, indexedDB: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,6 @@ export const waitForAllLoadersToDisappear = async (
await expect(loaders).toHaveCount(0, { timeout });
};

/**
* Force fresh table reads by stripping the client `If-None-Match` header on
* `/api/v1/tables/**` requests. The server ETag is derived only from the table's
* version/updatedAt, which child mutations (custom metrics, executable test suites)
* do not bump — so a post-mutation refetch can receive a not-modified response and
* render stale data. Removing the conditional header makes the server always return
* the current body, eliminating that stale-read flake in tests.
*/
export const forceFreshTableReads = async (page: Page) => {
await page.route('**/api/v1/tables/**', async (route) => {
const headers = route.request().headers();
delete headers['if-none-match'];
await route.continue({ headers });
});
};

export const visitEntityPage = async (data: {
page: Page;
searchTerm: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ import Qs from 'qs';
* GET response is 5-50 KB so the cap holds the cache to ~10 MB worst case.
*/

/**
* localStorage flag that opts a session out of client-side conditional (If-None-Match) reads.
*
* The server ETag is derived from the entity's version/updatedAt only, so it does not move for
* relationship-only or child mutations (followers, votes, customMetrics, testSuite). A refetch
* that races such a mutation can therefore be answered "not modified" and render a stale body.
* E2E runs set this flag in the Playwright auth setup, where it is persisted via storageState and
* inherited by every spec. Remove once the ETag reflects the requested fields and child state.
*/
export const DISABLE_ETAG_CONDITIONAL_READS_KEY =
'OM_DISABLE_ETAG_CONDITIONAL_READS';

interface CachedEntry {
etag: string;
data: unknown;
Expand Down
13 changes: 11 additions & 2 deletions openmetadata-ui/src/main/resources/ui/src/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import axios from 'axios';
import Qs from 'qs';
import { getBasePath } from '../utils/HistoryUtils';
import { attachEtagInterceptor } from './etagInterceptor';
import {
attachEtagInterceptor,
DISABLE_ETAG_CONDITIONAL_READS_KEY,
} from './etagInterceptor';

const axiosClient = axios.create({
baseURL: `${getBasePath()}/api/v1`,
Expand All @@ -25,6 +28,12 @@ const axiosClient = axios.create({
// response body bytes + a JSON parse + a render on entity GET revisits within a session.
// Attached here (before AuthProvider's interceptors) so it sits closest to the wire and
// every other interceptor sees the resolved 304→200-with-cached-body translation.
attachEtagInterceptor(axiosClient);
// Skipped when the session opts out (see DISABLE_ETAG_CONDITIONAL_READS_KEY).
if (
typeof localStorage === 'undefined' ||
localStorage.getItem(DISABLE_ETAG_CONDITIONAL_READS_KEY) !== 'true'
) {
attachEtagInterceptor(axiosClient);
}

export default axiosClient;
Loading