Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Oct 2, 2024
1 parent 0441201 commit fdb6e72
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export default function ({ getService }: FtrProviderContext) {
};

describe('Data Stream', function () {
const generatedReports = new Set<string>();
before(async () => {
roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin');
internalReqHeader = svlCommonApi.getInternalRequestHeader();

await esArchiver.load(archives.ecommerce.data);
await kibanaServer.importExport.load(archives.ecommerce.savedObjects);

// for this test, we don't need to wait for the job to finish or verify the result
await reportingAPI.createReportJobInternal(
const { job } = await reportingAPI.createReportJobInternal(
'csv_searchsource',
{
browserTimezone: 'UTC',
Expand All @@ -51,10 +51,15 @@ export default function ({ getService }: FtrProviderContext) {
roleAuthc,
internalReqHeader
);

generatedReports.add(job.id);
});

after(async () => {
await reportingAPI.deleteAllReports(roleAuthc, internalReqHeader);
for (const reportId of generatedReports) {
await reportingAPI.deleteReport(reportId, roleAuthc, internalReqHeader);
}

await esArchiver.unload(archives.ecommerce.data);
await kibanaServer.importExport.unload(archives.ecommerce.savedObjects);
await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export default function ({ getService }: FtrProviderContext) {
});

after(async () => {
await reportingAPI.deleteAllReports(roleAuthc, internalReqHeader);
await esArchiver.unload(archives.ecommerce.data);
await kibanaServer.importExport.unload(archives.ecommerce.savedObjects);
});
Expand Down
29 changes: 17 additions & 12 deletions x-pack/test_serverless/shared/services/svl_reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import expect from '@kbn/expect';
import { INTERNAL_ROUTES } from '@kbn/reporting-common';
import type { ReportingJobResponse } from '@kbn/reporting-plugin/server/types';
import { REPORTING_DATA_STREAM_WILDCARD_WITH_LEGACY } from '@kbn/reporting-server';
import rison from '@kbn/rison';
import { FtrProviderContext } from '../../functional/ftr_provider_context';
import { RoleCredentials } from '.';
Expand Down Expand Up @@ -111,17 +110,23 @@ export function SvlReportingServiceProvider({ getService }: FtrProviderContext)
.set(roleAuthc.apiKeyHeader);
return response.text as unknown;
},
async deleteAllReports(roleAuthc: RoleCredentials, internalReqHeader: InternalRequestHeader) {
log.debug('ReportingAPI.deleteAllReports');

// ignores 409 errs and keeps retrying
await retry.tryForTime(5000, async () => {
await supertestWithoutAuth
.post(`/${REPORTING_DATA_STREAM_WILDCARD_WITH_LEGACY}/_delete_by_query`)
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.send({ query: { match_all: {} } });
});

/*
* Ensures reports are cleaned up through the delete report API
*/
async deleteReport(
reportId: string,
roleAuthc: RoleCredentials,
internalReqHeader: InternalRequestHeader
) {
log.debug(`ReportingAPI.deleteReport ${INTERNAL_ROUTES.JOBS.DELETE_PREFIX}/${reportId}`);
const response = await supertestWithoutAuth
.delete(INTERNAL_ROUTES.JOBS.DELETE_PREFIX + `/${reportId}`)
.set(internalReqHeader)
.set(roleAuthc.apiKeyHeader)
.set('kbn-xsrf', 'xxx')
.expect(200);
return response.text as unknown;
},
};
}

0 comments on commit fdb6e72

Please sign in to comment.