Skip to content

Commit

Permalink
Add field list cache busting for functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Dec 15, 2023
1 parent d7701c7 commit 17c535f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class DataViewsApiClient implements IDataViewsApiClient {
} = options;
const path = indexFilter ? FIELDS_FOR_WILDCARD_PATH : FIELDS_PATH;
const versionQueryParam = indexFilter ? {} : { apiVersion: version };
const ftrCacheBuster = localStorage.getItem('dataViews:ftrCacheBuster');

return this._request<FieldsForWildcardResponse>(
path,
Expand All @@ -106,6 +107,7 @@ export class DataViewsApiClient implements IDataViewsApiClient {
fields,
allow_hidden: allowHidden,
...versionQueryParam,
...(ftrCacheBuster ? { ftrCacheBuster } : {}),
},
indexFilter ? JSON.stringify({ index_filter: indexFilter }) : undefined,
forceRefresh
Expand Down
16 changes: 10 additions & 6 deletions src/plugins/data_views/server/rest_api_routes/internal/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ export const registerFields = async (
>,
isRollupsEnabled: () => boolean
) => {
router.versioned
.get({ path, access: 'internal', enableQueryVersion: true })
.addVersion(
{ version: '1', validate: { request: { query: querySchema }, response: validate.response } },
handler(isRollupsEnabled)
);
router.versioned.get({ path, access: 'internal', enableQueryVersion: true }).addVersion(
{
version: '1',
validate: {
request: { query: querySchema.extends({}, { unknowns: 'ignore' }) },
response: validate.response,
},
},
handler(isRollupsEnabled)
);
};
17 changes: 2 additions & 15 deletions test/functional/page_objects/settings_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,21 +484,8 @@ export class SettingsPageObject extends FtrService {
}

async refreshDataViewFieldList(dataViewName?: string) {
if (dataViewName) {
await this.common.navigateToApp('management/kibana/dataViews');
await this.header.waitUntilLoadingHasFinished();
await this.testSubjects.click(`detail-link-${dataViewName}`);
}
await this.testSubjects.click('refreshDataViewButton');

// wait for refresh to start
await new Promise((r) => setTimeout(r, 500));

// wait for refresh to finish
await this.retry.try(async () => {
const btn = await this.testSubjects.find('refreshDataViewButton');
const disabled = await btn.getAttribute('disabled');
expect(disabled).to.be(null);
await this.browser.execute(() => {
localStorage.setItem('dataViews:ftrCacheBuster', Date.now().toString());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function (ctx: FtrProviderContext) {
'header',
'unifiedFieldList',
'settings',
'settings',
]);
const testSubjects = getService('testSubjects');
const appsMenu = getService('appsMenu');
Expand Down Expand Up @@ -448,20 +449,7 @@ export default function (ctx: FtrProviderContext) {
it('allows to access only via a permitted index alias', async () => {
await globalNav.badgeExistsOrFail('Read only');

// can't access logstash index directly
// swapping index patterns so we get an updated field list
// this is necessary since we don't have access to data view management
// nor can we force reload the browser in a test
await new Promise((resolve) => setTimeout(resolve, 5000));
await PageObjects.discover.selectIndexPattern('logstash-*');
await new Promise((resolve) => setTimeout(resolve, 5000));
await PageObjects.discover.selectIndexPattern('alias-logstash-discover');
await new Promise((resolve) => setTimeout(resolve, 5000));
await PageObjects.discover.selectIndexPattern('logstash-*');
await new Promise((resolve) => setTimeout(resolve, 5000));
await PageObjects.discover.selectIndexPattern('alias-logstash-discover');

await new Promise((resolve) => setTimeout(resolve, 5000));
await PageObjects.settings.refreshDataViewFieldList();
await PageObjects.discover.selectIndexPattern('logstash-*');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('discoverNoResultsCheckIndices');
Expand Down

0 comments on commit 17c535f

Please sign in to comment.