[Search] Re-enable test on example search app (#139961)

* [Search] Unskip ex-flaky example app test

* comment out flaky test code

* use es.transport.request to downsample the test index

* uncomment blocked test code

* remove browser refresh in beforeEach

* fix ts
This commit is contained in:
Tim Sullivan 2022-09-09 10:25:36 -07:00 committed by GitHub
parent a26cc71578
commit 95c3893e28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 61 deletions

View file

@ -107,9 +107,9 @@ export const SearchExamplesApp = ({
const [selectedBucketField, setSelectedBucketField] = useState<
DataViewField | null | undefined
>();
const [request, setRequest] = useState<Record<string, any>>({});
const [isLoading, setIsLoading] = useState<boolean>(false);
const [currentAbortController, setAbortController] = useState<AbortController>();
const [request, setRequest] = useState<Record<string, any>>({});
const [rawResponse, setRawResponse] = useState<Record<string, any>>({});
const [warningContents, setWarningContents] = useState<SearchResponseWarning[]>([]);
const [selectedTab, setSelectedTab] = useState(0);
@ -202,6 +202,8 @@ export const SearchExamplesApp = ({
// Submit the search request using the `data.search` service.
setRequest(req.params.body);
setRawResponse({});
setWarningContents([]);
setIsLoading(true);
data.search
@ -301,6 +303,8 @@ export const SearchExamplesApp = ({
searchSource.setField('aggs', ac);
}
setRequest(searchSource.getSearchRequestBody());
setRawResponse({});
setWarningContents([]);
const abortController = new AbortController();
const inspector: Required<IInspectorInfo> = {

View file

@ -6,15 +6,19 @@
* Side Public License, v 1.
*/
import type { estypes } from '@elastic/elasticsearch';
import expect from '@kbn/expect';
import { asyncForEach } from '@kbn/std';
import { FtrProviderContext } from '../../functional/ftr_provider_context';
import assert from 'assert';
import type { FtrProviderContext } from '../../functional/ftr_provider_context';
import type { WebElementWrapper } from '../../functional/services/lib/web_element_wrapper';
// eslint-disable-next-line import/no-default-export
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'timePicker']);
const testSubjects = getService('testSubjects');
const find = getService('find');
const retry = getService('retry');
const es = getService('es');
const log = getService('log');
const indexPatterns = getService('indexPatterns');
@ -22,8 +26,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');
const esArchiver = getService('esArchiver');
// Failing: See https://github.com/elastic/kibana/issues/139879
describe.skip('handling warnings with search source fetch', function () {
describe('handling warnings with search source fetch', function () {
const dataViewTitle = 'sample-01,sample-01-rollup';
const fromTime = 'Jun 17, 2022 @ 00:00:00.000';
const toTime = 'Jun 23, 2022 @ 00:00:00.000';
@ -51,10 +54,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await es.indices.addBlock({ index: testIndex, block: 'write' });
try {
log.info(`rolling up ${testIndex} index...`);
await es.rollup.rollup({
index: testIndex,
rollup_index: testRollupIndex,
config: { fixed_interval: '1h' },
// es client currently does not have method for downsample
await es.transport.request<void>({
method: 'POST',
path: '/sample-01/_downsample/sample-01-rollup',
body: { fixed_interval: '1h' },
});
} catch (err) {
log.info(`ignoring resource_already_exists_exception...`);
@ -76,6 +80,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
defaultIndex: '0ae0bc7a-e4ca-405c-ab67-f2b5913f2a51',
'timepicker:timeDefaults': '{ "from": "now-1y", "to": "now" }',
});
await PageObjects.common.navigateToApp('searchExamples');
});
beforeEach(async () => {
await comboBox.setCustom('dataViewSelector', dataViewTitle);
await comboBox.set('searchMetricField', testRollupField);
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
});
after(async () => {
@ -84,64 +96,20 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await kibanaServer.uiSettings.replace({});
});
beforeEach(async () => {
// reload the page to clear toasts from previous test
await PageObjects.common.navigateToApp('searchExamples');
await comboBox.setCustom('dataViewSelector', dataViewTitle);
await comboBox.set('searchMetricField', testRollupField);
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
afterEach(async () => {
await PageObjects.common.clearAllToasts();
});
it('shows shard failure warning notifications by default', async () => {
await testSubjects.click('searchSourceWithOther');
// toasts
const toasts = await find.allByCssSelector(toastsSelector);
expect(toasts.length).to.be(3);
const expects = ['2 of 4 shards failed', '2 of 4 shards failed', 'Query result']; // BUG: there are 2 shards failed toast notifications
await asyncForEach(toasts, async (t, index) => {
expect(await t.getVisibleText()).to.eql(expects[index]);
// wait for response - toasts appear before the response is rendered
let response: estypes.SearchResponse | undefined;
await retry.try(async () => {
response = await getTestJson('responseTab', 'responseCodeBlock');
expect(response).not.to.eql({});
});
// click "see full error" button in the toast
const [openShardModalButton] = await testSubjects.findAll('openShardFailureModalBtn');
await openShardModalButton.click();
const modalHeader = await testSubjects.find('shardFailureModalTitle');
expect(await modalHeader.getVisibleText()).to.be('2 of 4 shards failed');
// request
await testSubjects.click('shardFailuresModalRequestButton');
const requestBlock = await testSubjects.find('shardsFailedModalRequestBlock');
expect(await requestBlock.getVisibleText()).to.contain(testRollupField);
// response
await testSubjects.click('shardFailuresModalResponseButton');
const responseBlock = await testSubjects.find('shardsFailedModalResponseBlock');
expect(await responseBlock.getVisibleText()).to.contain(shardFailureReason);
// close things
await testSubjects.click('closeShardFailureModal');
await PageObjects.common.clearAllToasts();
// response tab
const response = await getTestJson('responseTab', 'responseCodeBlock');
expect(response._shards.total).to.be(4);
expect(response._shards.successful).to.be(2);
expect(response._shards.skipped).to.be(0);
expect(response._shards.failed).to.be(2);
expect(response._shards.failures.length).to.equal(1);
expect(response._shards.failures[0].index).to.equal(testRollupIndex);
expect(response._shards.failures[0].reason.type).to.equal(shardFailureType);
expect(response._shards.failures[0].reason.reason).to.equal(shardFailureReason);
// warnings tab
const warnings = await getTestJson('warningsTab', 'warningsCodeBlock');
expect(warnings).to.eql([]);
});
it('able to handle shard failure warnings and prevent default notifications', async () => {
await testSubjects.click('searchSourceWithoutOther');
// toasts
const toasts = await find.allByCssSelector(toastsSelector);
expect(toasts.length).to.be(2);
@ -164,9 +132,53 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const responseBlock = await testSubjects.find('shardsFailedModalResponseBlock');
expect(await responseBlock.getVisibleText()).to.contain(shardFailureReason);
// close things
await testSubjects.click('closeShardFailureModal');
await PageObjects.common.clearAllToasts();
// response tab
assert(response && response._shards.failures);
expect(response._shards.total).to.be(4);
expect(response._shards.successful).to.be(2);
expect(response._shards.skipped).to.be(0);
expect(response._shards.failed).to.be(2);
expect(response._shards.failures.length).to.equal(1);
expect(response._shards.failures[0].index).to.equal(testRollupIndex);
expect(response._shards.failures[0].reason.type).to.equal(shardFailureType);
expect(response._shards.failures[0].reason.reason).to.equal(shardFailureReason);
// warnings tab
const warnings = await getTestJson('warningsTab', 'warningsCodeBlock');
expect(warnings).to.eql([]);
});
it('able to handle shard failure warnings and prevent default notifications', async () => {
await testSubjects.click('searchSourceWithoutOther');
// wait for toasts - toasts appear after the response is rendered
let toasts: WebElementWrapper[] = [];
await retry.try(async () => {
toasts = await find.allByCssSelector(toastsSelector);
expect(toasts.length).to.be(2);
});
const expects = ['2 of 4 shards failed', 'Query result'];
await asyncForEach(toasts, async (t, index) => {
expect(await t.getVisibleText()).to.eql(expects[index]);
});
// click "see full error" button in the toast
const [openShardModalButton] = await testSubjects.findAll('openShardFailureModalBtn');
await openShardModalButton.click();
const modalHeader = await testSubjects.find('shardFailureModalTitle');
expect(await modalHeader.getVisibleText()).to.be('2 of 4 shards failed');
// request
await testSubjects.click('shardFailuresModalRequestButton');
const requestBlock = await testSubjects.find('shardsFailedModalRequestBlock');
expect(await requestBlock.getVisibleText()).to.contain(testRollupField);
// response
await testSubjects.click('shardFailuresModalResponseButton');
const responseBlock = await testSubjects.find('shardsFailedModalResponseBlock');
expect(await responseBlock.getVisibleText()).to.contain(shardFailureReason);
await testSubjects.click('closeShardFailureModal');
// response tab
const response = await getTestJson('responseTab', 'responseCodeBlock');