Skip to content

Commit

Permalink
[reporting/upgrade/tests] rewrite waitForJobToFinish to handle errors (
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored Mar 22, 2022
1 parent 4cd7f87 commit a28b25a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const schema = Joi.object()
try: Joi.number().default(120000),
waitFor: Joi.number().default(20000),
esRequestTimeout: Joi.number().default(30000),
kibanaReportCompletion: Joi.number().default(60_000),
kibanaStabilize: Joi.number().default(15000),
navigateStatusPageCheck: Joi.number().default(250),

Expand Down Expand Up @@ -166,7 +167,9 @@ export const schema = Joi.object()

mochaReporter: Joi.object()
.keys({
captureLogOutput: Joi.boolean().default(!!process.env.CI),
captureLogOutput: Joi.boolean().default(
!!process.env.CI && !process.env.DISABLE_CI_LOG_OUTPUT_CAPTURE
),
sendToCiStats: Joi.boolean().default(!!process.env.CI),
})
.default(),
Expand Down
8 changes: 3 additions & 5 deletions x-pack/test/upgrade/apps/reporting/reporting_smoke_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const postUrl = await find.byXPath(`//button[descendant::*[text()='Copy POST URL']]`);
await postUrl.click();
const url = await browser.getClipboardValue();
await reportingAPI.expectAllJobsToFinishSuccessfully(
await Promise.all([
reportingAPI.postJob(parse(url).pathname + '?' + parse(url).query),
])
);
await reportingAPI.expectAllJobsToFinishSuccessfully([
await reportingAPI.postJob(parse(url).pathname + '?' + parse(url).query),
]);
usage = (await usageAPI.getUsageStats()) as UsageStats;
reportingAPI.expectCompletedReportCount(usage, completedReportCount + 1);
});
Expand Down
39 changes: 20 additions & 19 deletions x-pack/test/upgrade/reporting_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,34 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esSupertest = getService('esSupertest');
const retry = getService('retry');
const config = getService('config');

return {
async waitForJobToFinish(downloadReportPath: string) {
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
async waitForJobToFinish(downloadReportPath: string, options?: { timeout?: number }) {
await retry.waitForWithTimeout(
`job ${downloadReportPath} finished`,
options?.timeout ?? config.get('timeouts.kibanaReportCompletion'),
async () => {
const response = await supertest
.get(downloadReportPath)
.responseType('blob')
.set('kbn-xsrf', 'xxx')) as any;
if (response.statusCode === 503) {
.set('kbn-xsrf', 'xxx');

if (response.status === 503) {
log.debug(`Report at path ${downloadReportPath} is pending`);
} else if (response.statusCode === 200) {
log.debug(`Report at path ${downloadReportPath} is complete`);
} else {
log.debug(`Report at path ${downloadReportPath} returned code ${response.statusCode}`);
return false;
}
if (response.statusCode !== JOB_IS_PENDING_CODE) {
clearInterval(intervalId);
resolve(response.statusCode);

log.debug(`Report at path ${downloadReportPath} returned code ${response.status}`);

if (response.status === 200) {
log.debug(`Report at path ${downloadReportPath} is complete`);
return true;
}
}, 1500);
});

expect(statusCode).to.be(200);
throw new Error(`unexpected status code ${response.status}`);
}
);
},

async expectAllJobsToFinishSuccessfully(jobPaths: string[]) {
Expand Down

0 comments on commit a28b25a

Please sign in to comment.