Skip to content

Commit

Permalink
fix test service
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Aug 4, 2021
1 parent bf56197 commit 373b187
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions x-pack/test/reporting_api_integration/services/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import expect from '@kbn/expect';
import { indexTimestamp } from '../../../plugins/reporting/server/lib/store/index_timestamp';
import { FtrProviderContext } from '../ftr_provider_context';

interface PDFAppCounts {
Expand Down Expand Up @@ -37,6 +38,7 @@ export interface UsageStats {

export function createUsageServices({ getService }: FtrProviderContext) {
const log = getService('log');
const esSupertest = getService('esSupertest');
const supertest = getService('supertest');

return {
Expand Down Expand Up @@ -67,6 +69,42 @@ export function createUsageServices({ getService }: FtrProviderContext) {
expect(statusCode).to.be(200);
},

/**
*
* @return {Promise<Function>} A function to call to clean up the index alias that was added.
*/
async coerceReportsIntoExistingIndex(indexName: string) {
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 expectAllJobsToFinishSuccessfully(jobPaths: string[]) {
await Promise.all(
jobPaths.map(async (path) => {
Expand Down

0 comments on commit 373b187

Please sign in to comment.