From a34e01a83649a210ae071fe020969793bb4089fa Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Thu, 13 Dec 2018 17:56:35 -0700 Subject: [PATCH] [Reporting] Re-enable some skipped tests (#27094) (#27177) * [Test/Reporting] Enable "generates a report with/without data" * navigate to discover before each csv test * get another test working * re-enable more tests * refactor api usage tests * catch error in createIndex to avoid race condition in test * delete reports before --- .../lib/esqueue/helpers/create_index.js | 12 ++- x-pack/test/reporting/api/usage.js | 84 ++++++++++++------- x-pack/test/reporting/functional/reporting.js | 7 +- 3 files changed, 68 insertions(+), 35 deletions(-) diff --git a/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js b/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js index 45be7529e688..bf58039e424d 100644 --- a/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js +++ b/x-pack/plugins/reporting/server/lib/esqueue/helpers/create_index.js @@ -88,7 +88,17 @@ export function createIndex(client, indexName, index: indexName, body: body }) - .then(() => true); + .then(() => true) + .catch(err => { + /* FIXME creating the index will fail if there were multiple jobs staged in parallel. + * Each staged job checks `client.indices.exists` and could each get `false` as a response. + * Only the first job in line can successfully create it though. + * The problem might only happen in automated tests, where the indices are deleted after each test run. + * This catch block is in place to not fail a job if the job runner hits this race condition. + * Unfortunately we don't have a logger in scope to log a warning. + */ + err; // no-op + }); } return exists; }); diff --git a/x-pack/test/reporting/api/usage.js b/x-pack/test/reporting/api/usage.js index 53f292b7bf70..3c2c5799178f 100644 --- a/x-pack/test/reporting/api/usage.js +++ b/x-pack/test/reporting/api/usage.js @@ -13,11 +13,10 @@ export default function ({ getService }) { const usageAPI = getService('usageAPI'); describe('reporting usage', () => { - before(async () => { - await reportingAPI.deleteAllReportingIndexes(); - }); + before(() => reportingAPI.deleteAllReportingIndexes()); + afterEach(() => reportingAPI.deleteAllReportingIndexes()); - describe('initial usage', () => { + describe('initial state', () => { let usage; before(async () => { @@ -45,7 +44,7 @@ export default function ({ getService }) { }); }); - describe('includes usage from reporting indexes', () => { + describe('from archive data', () => { it('generated from 6.2', async () => { await esArchiver.load('bwc/6_2'); const usage = await usageAPI.getUsageStats(); @@ -79,8 +78,8 @@ export default function ({ getService }) { reportingAPI.expectRecentPdfLayoutStats(usage, 'preserve_layout', 0); reportingAPI.expectRecentPdfLayoutStats(usage, 'print', 0); - reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'csv', 3); - reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'printable_pdf', 19); + reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'csv', 2); + reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'printable_pdf', 12); reportingAPI.expectAllTimePdfAppStats(usage, 'visualization', 3); reportingAPI.expectAllTimePdfAppStats(usage, 'dashboard', 3); reportingAPI.expectAllTimePdfLayoutStats(usage, 'preserve_layout', 3); @@ -88,35 +87,56 @@ export default function ({ getService }) { }); }); - describe('usage updated when new jobs are posted', async () => { - it('post jobs', async () => { - const reportPaths = []; - reportPaths.push(await reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3)); - reportPaths.push(await reportingAPI.postJob(GenerationUrls.PDF_PRESERVE_DASHBOARD_FILTER_6_3)); - reportPaths.push(await reportingAPI.postJob(GenerationUrls.PDF_PRESERVE_PIE_VISUALIZATION_6_3)); - reportPaths.push(await reportingAPI.postJob(GenerationUrls.PDF_PRINT_DASHBOARD_6_3)); - reportPaths.push(await reportingAPI.postJob( - GenerationUrls.PDF_PRINT_PIE_VISUALIZATION_FILTER_AND_SAVED_SEARCH_6_3)); + describe('from new jobs posted', () => { + it('csv', async () => { + await reportingAPI.expectAllJobsToFinishSuccessfully(await Promise.all([ + reportingAPI.postJob(GenerationUrls.CSV_DISCOVER_KUERY_AND_FILTER_6_3), + ])); - await reportingAPI.expectAllJobsToFinishSuccessfully(reportPaths); - }).timeout(1540000); - - it('usage updated', async () => { const usage = await usageAPI.getUsageStats(); - - reportingAPI.expectRecentPdfAppStats(usage, 'visualization', 2); - reportingAPI.expectRecentPdfAppStats(usage, 'dashboard', 2); - reportingAPI.expectRecentPdfLayoutStats(usage, 'preserve_layout', 2); - reportingAPI.expectRecentPdfLayoutStats(usage, 'print', 2); + reportingAPI.expectRecentPdfAppStats(usage, 'visualization', 0); + reportingAPI.expectRecentPdfAppStats(usage, 'dashboard', 0); + reportingAPI.expectRecentPdfLayoutStats(usage, 'preserve_layout', 0); + reportingAPI.expectRecentPdfLayoutStats(usage, 'print', 0); reportingAPI.expectRecentJobTypeTotalStats(usage, 'csv', 1); - reportingAPI.expectRecentJobTypeTotalStats(usage, 'printable_pdf', 4); + reportingAPI.expectRecentJobTypeTotalStats(usage, 'printable_pdf', 0); + }); - reportingAPI.expectAllTimePdfAppStats(usage, 'visualization', 5); - reportingAPI.expectAllTimePdfAppStats(usage, 'dashboard', 5); - reportingAPI.expectAllTimePdfLayoutStats(usage, 'preserve_layout', 5); - reportingAPI.expectAllTimePdfLayoutStats(usage, 'print', 5); - reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'csv', 4); - reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'printable_pdf', 23); + it('preserve_layout pdf', async () => { + await reportingAPI.expectAllJobsToFinishSuccessfully(await Promise.all([ + reportingAPI.postJob(GenerationUrls.PDF_PRESERVE_DASHBOARD_FILTER_6_3), + reportingAPI.postJob(GenerationUrls.PDF_PRESERVE_PIE_VISUALIZATION_6_3), + ])); + + const usage = await usageAPI.getUsageStats(); + reportingAPI.expectRecentPdfAppStats(usage, 'visualization', 1); + reportingAPI.expectRecentPdfAppStats(usage, 'dashboard', 1); + reportingAPI.expectRecentPdfLayoutStats(usage, 'preserve_layout', 2); + reportingAPI.expectRecentPdfLayoutStats(usage, 'print', 0); + reportingAPI.expectRecentJobTypeTotalStats(usage, 'csv', 0); + reportingAPI.expectRecentJobTypeTotalStats(usage, 'printable_pdf', 2); + }); + + it('print_layout pdf', async () => { + await reportingAPI.expectAllJobsToFinishSuccessfully(await Promise.all([ + reportingAPI.postJob(GenerationUrls.PDF_PRINT_DASHBOARD_6_3), + reportingAPI.postJob(GenerationUrls.PDF_PRINT_PIE_VISUALIZATION_FILTER_AND_SAVED_SEARCH_6_3), + ])); + + const usage = await usageAPI.getUsageStats(); + reportingAPI.expectRecentPdfAppStats(usage, 'visualization', 1); + reportingAPI.expectRecentPdfAppStats(usage, 'dashboard', 1); + reportingAPI.expectRecentPdfLayoutStats(usage, 'preserve_layout', 0); + reportingAPI.expectRecentPdfLayoutStats(usage, 'print', 2); + reportingAPI.expectRecentJobTypeTotalStats(usage, 'csv', 0); + reportingAPI.expectRecentJobTypeTotalStats(usage, 'printable_pdf', 2); + + reportingAPI.expectAllTimePdfAppStats(usage, 'visualization', 1); + reportingAPI.expectAllTimePdfAppStats(usage, 'dashboard', 1); + reportingAPI.expectAllTimePdfLayoutStats(usage, 'preserve_layout', 0); + reportingAPI.expectAllTimePdfLayoutStats(usage, 'print', 2); + reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'csv', 0); + reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'printable_pdf', 2); }); }); }); diff --git a/x-pack/test/reporting/functional/reporting.js b/x-pack/test/reporting/functional/reporting.js index 76acff0dde8b..b9e507e62081 100644 --- a/x-pack/test/reporting/functional/reporting.js +++ b/x-pack/test/reporting/functional/reporting.js @@ -263,26 +263,29 @@ export default function ({ getService, getPageObjects }) { describe('Discover', () => { describe('Generate CSV button', () => { + beforeEach(() => PageObjects.common.navigateToApp('discover')); + it('is not available if new', async () => { - await PageObjects.common.navigateToApp('discover'); await PageObjects.reporting.openCsvReportingPanel(); await expectDisabledGenerateReportButton(); }); it('becomes available when saved', async () => { - await PageObjects.discover.saveSearch('my search'); + await PageObjects.discover.saveSearch('my search - expectEnabledGenerateReportButton'); await PageObjects.reporting.openCsvReportingPanel(); await expectEnabledGenerateReportButton(); }); it('generates a report with data', async () => { await PageObjects.reporting.setTimepickerInDataRange(); + await PageObjects.discover.saveSearch('my search - with data - expectReportCanBeCreated'); await PageObjects.reporting.openCsvReportingPanel(); await expectReportCanBeCreated(); }); it('generates a report with no data', async () => { await PageObjects.reporting.setTimepickerInNoDataRange(); + await PageObjects.discover.saveSearch('my search - no data - expectReportCanBeCreated'); await PageObjects.reporting.openCsvReportingPanel(); await expectReportCanBeCreated(); });