kibana/x-pack/test/reporting/services/reporting_api.js
Stacey Gammon c639deba73
Move all reporting tests into their own folder and add chromium tests (#19330)
* Move all reporting tests into their own folder to allow for multiple kibana.yml configuration tests, including chromium

* Add debugging and try to skip other tests an jenkins to speed things up

* More debug output

* more logging (remove other line which failed on jenkins)

* Remove no sandbox flag, it doesn't help

* Add fix for socket hangup and clean up tests

* fix path to logstash_functional

* Extend timeout for chromium, add verbose logging, add better comment, conditionally output curl command

* fix path... again

* Ah, other functional tests still need access to reporting page object, put it back

* fix sp err

* Add debug logs for screenshot stitching for png.bitblt error

* Fix tests that don't pass logger to screenshotStitcher

* Fix logger being undefined

* Add more debug output

* png has data, too much info to spit out

* Add comment with link to issue for extra debug messages so they can be left in since so many passes

* Dont use spawnSync with curl, use http.request instead, more support for it

* Comment out chromium tests for now to avoid flakiness

* Wait... lets at least make sure the other fix worked (the http.request instead of spawnsync and curl)

* New http.request code doesn't seem to work on jenkins, timing out after 10 secs maybe

* go back to spawnsync to see if it's an issue with the rxjs code or the http.request code

* I think I figured it out...

* Comment out tests to avoid flaky png error in the screenshot stitcher

* Use a const for OSS archive path

* use path.resolve correctly.
2018-06-05 18:41:23 -04:00

135 lines
4.3 KiB
JavaScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import expect from 'expect.js';
import { indexTimestamp } from '../../../plugins/reporting/server/lib/esqueue/helpers/index_timestamp';
function removeWhitespace(str) {
return str.replace(/\s/g, '');
}
export function ReportingAPIProvider({ getService }) {
const log = getService('log');
const supertest = getService('supertest');
const esSupertest = getService('esSupertest');
return {
async waitForJobToFinish(downloadReportPath) {
log.debug(`Waiting for job to finish: ${downloadReportPath}`);
const JOB_IS_PENDING_CODE = 503;
const statusCode = await new Promise(resolve => {
const intervalId = setInterval(async () => {
const response = await supertest
.get(downloadReportPath)
.responseType('blob')
.set('kbn-xsrf', 'xxx');
log.debug(`Report at path ${downloadReportPath} returned code ${response.statusCode}`);
if (response.statusCode !== JOB_IS_PENDING_CODE) {
clearInterval(intervalId);
resolve(response.statusCode);
}
}, 1500);
});
expect(statusCode).to.be(200);
},
async expectAllJobsToFinishSuccessfully(jobPaths) {
await Promise.all(jobPaths.map(async (path) => {
await this.waitForJobToFinish(path);
}));
},
async postJob(apiPath) {
log.debug(`ReportingAPI.postJob(${apiPath})`);
const { body } = await supertest
.post(removeWhitespace(apiPath))
.set('kbn-xsrf', 'xxx')
.expect(200);
return body.path;
},
/**
*
* @return {Promise<Function>} A function to call to clean up the index alias that was added.
*/
async coerceReportsIntoExistingIndex(indexName) {
log.debug(`ReportingAPI.coerceReportsIntoExistingIndex(${indexName})`);
// Adding an index alias coerces the report to be generated on an existing index which means any new
// index schema won't be applied. This is important if a point release updated the schema. Reports may still
// be inserted into an existing index before the new schema is applied.
const timestampForIndex = indexTimestamp('week', '.');
await esSupertest
.post('/_aliases')
.send({
actions: [
{
add: { index: indexName, alias: `.reporting-${timestampForIndex}` }
}
]
})
.expect(200);
return async () => {
await esSupertest
.post('/_aliases')
.send({
actions: [
{
remove: { index: indexName, alias: `.reporting-${timestampForIndex}` }
}
]
})
.expect(200);
};
},
async deleteAllReportingIndexes() {
log.debug('ReportingAPI.deleteAllReportingIndexes');
await esSupertest
.delete('/.reporting*')
.expect(200);
},
expectRecentPdfAppStats(stats, app, count) {
expect(stats.reporting.lastDay.printable_pdf.app[app]).to.be(count);
expect(stats.reporting.last7Days.printable_pdf.app[app]).to.be(count);
},
expectAllTimePdfAppStats(stats, app, count) {
expect(stats.reporting.printable_pdf.app[app]).to.be(count);
},
expectRecentPdfLayoutStats(stats, layout, count) {
expect(stats.reporting.lastDay.printable_pdf.layout[layout]).to.be(count);
expect(stats.reporting.last7Days.printable_pdf.layout[layout]).to.be(count);
},
expectAllTimePdfLayoutStats(stats, layout, count) {
expect(stats.reporting.printable_pdf.layout[layout]).to.be(count);
},
expectRecentJobTypeTotalStats(stats, jobType, count) {
expect(stats.reporting.lastDay[jobType].total).to.be(count);
expect(stats.reporting.last7Days[jobType].total).to.be(count);
},
expectAllTimeJobTypeTotalStats(stats, jobType, count) {
expect(stats.reporting[jobType].total).to.be(count);
},
getCompletedReportCount(stats) {
return stats.reporting.status.completed;
},
expectCompletedReportCount(stats, count) {
expect(this.getCompletedReportCount(stats)).to.be(count);
}
};
}