Skip to content

Commit fa30292

Browse files
authored
[Discover] Reintroduce ESQL request count tests (#204925)
1 parent cdbcfd7 commit fa30292

File tree

1 file changed

+112
-45
lines changed

1 file changed

+112
-45
lines changed

test/functional/apps/discover/group3/_request_counts.ts

Lines changed: 112 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
2121
]);
2222
const testSubjects = getService('testSubjects');
2323
const browser = getService('browser');
24+
const monacoEditor = getService('monacoEditor');
2425
const filterBar = getService('filterBar');
2526
const queryBar = getService('queryBar');
2627
const elasticChart = getService('elasticChart');
28+
const log = getService('log');
29+
const retry = getService('retry');
2730

2831
describe('discover request counts', function describeIndexTests() {
2932
before(async function () {
@@ -39,6 +42,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
3942
enableESQL: true,
4043
});
4144
await timePicker.setDefaultAbsoluteRangeViaUiSettings();
45+
await common.navigateToApp('discover');
46+
await header.waitUntilLoadingHasFinished();
4247
});
4348

4449
after(async () => {
@@ -47,18 +52,31 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
4752
await kibanaServer.uiSettings.replace({});
4853
});
4954

50-
beforeEach(async () => {
51-
await common.navigateToApp('discover');
52-
await header.waitUntilLoadingHasFinished();
53-
});
55+
const expectSearchCount = async (type: 'ese' | 'esql', searchCount: number) => {
56+
await retry.try(async () => {
57+
if (searchCount === 0) {
58+
await browser.execute(async () => {
59+
performance.clearResourceTimings();
60+
});
61+
}
62+
await waitForLoadingToFinish();
63+
const endpoint = type === 'esql' ? `${type}_async` : type;
64+
const requests = await browser.execute(() =>
65+
performance
66+
.getEntries()
67+
.filter((entry: any) => ['fetch', 'xmlhttprequest'].includes(entry.initiatorType))
68+
);
5469

55-
const getSearchCount = async (type: 'ese' | 'esql') => {
56-
const requests = await browser.execute(() =>
57-
performance
58-
.getEntries()
59-
.filter((entry: any) => ['fetch', 'xmlhttprequest'].includes(entry.initiatorType))
60-
);
61-
return requests.filter((entry) => entry.name.endsWith(`/internal/search/${type}`)).length;
70+
const result = requests.filter((entry) =>
71+
entry.name.endsWith(`/internal/search/${endpoint}`)
72+
);
73+
74+
const count = result.length;
75+
if (count !== searchCount) {
76+
log.warning('Request count differs:', result);
77+
}
78+
expect(count).to.be(searchCount);
79+
});
6280
};
6381

6482
const waitForLoadingToFinish = async () => {
@@ -68,15 +86,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
6886
};
6987

7088
const expectSearches = async (type: 'ese' | 'esql', expected: number, cb: Function) => {
71-
await browser.execute(async () => {
72-
performance.clearResourceTimings();
73-
});
74-
let searchCount = await getSearchCount(type);
75-
expect(searchCount).to.be(0);
89+
await expectSearchCount(type, 0);
7690
await cb();
77-
await waitForLoadingToFinish();
78-
searchCount = await getSearchCount(type);
79-
expect(searchCount).to.be(expected);
91+
await expectSearchCount(type, expected);
8092
};
8193

8294
const getSharedTests = ({
@@ -103,8 +115,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
103115
performance.setResourceTimingBufferSize(Number.MAX_SAFE_INTEGER);
104116
});
105117
await waitForLoadingToFinish();
106-
const searchCount = await getSearchCount(type);
107-
expect(searchCount).to.be(expectedRequests);
118+
// one more requests for fields in ESQL mode
119+
const actualExpectedRequests = type === 'esql' ? expectedRequests + 1 : expectedRequests;
120+
await expectSearchCount(type, actualExpectedRequests);
108121
});
109122

110123
it(`should send no more than ${expectedRequests} requests (documents + chart) when refreshing`, async () => {
@@ -121,12 +134,16 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
121134
});
122135

123136
it(`should send no more than ${expectedRequests} requests (documents + chart) when changing the time range`, async () => {
124-
await expectSearches(type, expectedRequests, async () => {
125-
await timePicker.setAbsoluteRange(
126-
'Sep 21, 2015 @ 06:31:44.000',
127-
'Sep 23, 2015 @ 00:00:00.000'
128-
);
129-
});
137+
await expectSearches(
138+
type,
139+
type === 'esql' ? expectedRequests + 1 : expectedRequests,
140+
async () => {
141+
await timePicker.setAbsoluteRange(
142+
'Sep 21, 2015 @ 06:31:44.000',
143+
'Sep 23, 2015 @ 00:00:00.000'
144+
);
145+
}
146+
);
130147
});
131148

132149
it(`should send ${savedSearchesRequests} requests for saved search changes`, async () => {
@@ -137,35 +154,50 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
137154
'Sep 23, 2015 @ 00:00:00.000'
138155
);
139156
await waitForLoadingToFinish();
140-
// TODO: Check why the request happens 4 times in case of opening a saved search
141-
// https://github.com/elastic/kibana/issues/165192
142-
// creating the saved search
143-
await expectSearches(type, savedSearchesRequests ?? expectedRequests, async () => {
144-
await discover.saveSearch(savedSearch);
145-
});
146-
// resetting the saved search
157+
const actualExpectedRequests = savedSearchesRequests ?? expectedRequests;
158+
log.debug('Creating saved search');
159+
await expectSearches(
160+
type,
161+
type === 'esql' ? actualExpectedRequests + 2 : actualExpectedRequests,
162+
async () => {
163+
await discover.saveSearch(savedSearch);
164+
}
165+
);
166+
log.debug('Resetting saved search');
147167
await setQuery(query2);
148168
await queryBar.clickQuerySubmitButton();
149169
await waitForLoadingToFinish();
150-
await expectSearches(type, expectedRequests, async () => {
170+
await expectSearches(type, actualExpectedRequests, async () => {
151171
await discover.revertUnsavedChanges();
152172
});
153-
// clearing the saved search
154-
await expectSearches('ese', savedSearchesRequests ?? expectedRequests, async () => {
155-
await testSubjects.click('discoverNewButton');
156-
await waitForLoadingToFinish();
157-
});
158-
// loading the saved search
159-
// TODO: https://github.com/elastic/kibana/issues/165192
160-
await expectSearches(type, savedSearchesRequests ?? expectedRequests, async () => {
161-
await discover.loadSavedSearch(savedSearch);
162-
});
173+
log.debug('Clearing saved search');
174+
await expectSearches(
175+
type,
176+
type === 'esql' ? actualExpectedRequests + 2 : actualExpectedRequests,
177+
async () => {
178+
await testSubjects.click('discoverNewButton');
179+
await waitForLoadingToFinish();
180+
}
181+
);
182+
log.debug('Loading saved search');
183+
await expectSearches(
184+
type,
185+
type === 'esql' ? actualExpectedRequests + 2 : actualExpectedRequests,
186+
async () => {
187+
await discover.loadSavedSearch(savedSearch);
188+
}
189+
);
163190
});
164191
};
165192

166193
describe('data view mode', () => {
167194
const type = 'ese';
168195

196+
beforeEach(async () => {
197+
await common.navigateToApp('discover');
198+
await header.waitUntilLoadingHasFinished();
199+
});
200+
169201
getSharedTests({
170202
type,
171203
savedSearch: 'data view test',
@@ -206,6 +238,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
206238
});
207239

208240
it('should send no more than 3 requests (documents + chart + other bucket) when changing to a breakdown field with an other bucket', async () => {
241+
await testSubjects.click('discoverNewButton');
209242
await expectSearches(type, 3, async () => {
210243
await discover.chooseBreakdownField('extension.raw');
211244
});
@@ -223,5 +256,39 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
223256
});
224257
});
225258
});
259+
260+
describe('ES|QL mode', () => {
261+
const type = 'esql';
262+
before(async () => {
263+
await common.navigateToApp('discover');
264+
await header.waitUntilLoadingHasFinished();
265+
await discover.selectTextBaseLang();
266+
});
267+
268+
beforeEach(async () => {
269+
await monacoEditor.setCodeEditorValue('from logstash-* | where bytes > 1000 ');
270+
await queryBar.clickQuerySubmitButton();
271+
await waitForLoadingToFinish();
272+
});
273+
274+
getSharedTests({
275+
type,
276+
savedSearch: 'esql test',
277+
query1: 'from logstash-* | where bytes > 1000 ',
278+
query2: 'from logstash-* | where bytes < 2000 ',
279+
savedSearchesRequests: 2,
280+
setQuery: (query) => monacoEditor.setCodeEditorValue(query),
281+
expectedRequests: 2,
282+
});
283+
284+
it(`should send requests (documents + chart) when toggling the chart visibility`, async () => {
285+
await expectSearches(type, 1, async () => {
286+
await discover.toggleChartVisibility();
287+
});
288+
await expectSearches(type, 3, async () => {
289+
await discover.toggleChartVisibility();
290+
});
291+
});
292+
});
226293
});
227294
}

0 commit comments

Comments
 (0)