Skip to content

Commit

Permalink
revert and use retry common util
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Jun 3, 2021
1 parent a8f8599 commit 2e8d126
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 245 deletions.
1 change: 0 additions & 1 deletion test/api_integration/apis/telemetry/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@

export { flatKeys } from './flat_keys';
export { assertTelemetryPayload } from './schema_to_config_schema';
export { tryAssertionUntil } from './try_assertion_until';
145 changes: 0 additions & 145 deletions test/api_integration/apis/telemetry/utils/try_assertion_until.test.js

This file was deleted.

53 changes: 0 additions & 53 deletions test/api_integration/apis/telemetry/utils/try_assertion_until.ts

This file was deleted.

77 changes: 31 additions & 46 deletions test/api_integration/apis/ui_counters/ui_counters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { ReportManager, METRIC_TYPE, UiCounterMetricType, Report } from '@kbn/an
import moment from 'moment';
import { FtrProviderContext } from '../../ftr_provider_context';
import { UsageCountersSavedObject } from '../../../../src/plugins/usage_collection/server';
import { tryAssertionUntil } from '../telemetry/utils';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
const retry = getService('retry');

const createUiCounterEvent = (eventName: string, type: UiCounterMetricType, count = 1) => ({
eventName,
Expand Down Expand Up @@ -69,22 +69,15 @@ export default function ({ getService }: FtrProviderContext) {

await sendReport(report);

await tryAssertionUntil(
async () => await fetchUsageCountersObjects(),
(savedObjects) => {
if (!savedObjects) {
return false;
}

const countTypeEvent = getCounterById(
savedObjects,
`uiCounter:${dayDate}:${METRIC_TYPE.COUNT}:myApp:my_event`
);
expect(countTypeEvent.attributes.count).to.eql(1);
},
4,
2000
);
await retry.waitForWithTimeout('reported events to be stored into ES', 8000, async () => {
const savedObjects = await fetchUsageCountersObjects();
const countTypeEvent = getCounterById(
savedObjects,
`uiCounter:${dayDate}:${METRIC_TYPE.COUNT}:myApp:my_event`
);
expect(countTypeEvent.attributes.count).to.eql(1);
return true;
});
});

it('supports multiple events', async () => {
Expand All @@ -99,35 +92,27 @@ export default function ({ getService }: FtrProviderContext) {
]);

await sendReport(report);

await tryAssertionUntil(
async () => await fetchUsageCountersObjects(),
(savedObjects) => {
if (!savedObjects) {
return false;
}

const countTypeEvent = getCounterById(
savedObjects,
`uiCounter:${dayDate}:${METRIC_TYPE.COUNT}:myApp:${uniqueEventName}`
);
expect(countTypeEvent.attributes.count).to.eql(1);

const clickTypeEvent = getCounterById(
savedObjects,
`uiCounter:${dayDate}:${METRIC_TYPE.CLICK}:myApp:${uniqueEventName}`
);
expect(clickTypeEvent.attributes.count).to.eql(2);

const secondEvent = getCounterById(
savedObjects,
`uiCounter:${dayDate}:${METRIC_TYPE.COUNT}:myApp:${uniqueEventName}_2`
);
expect(secondEvent.attributes.count).to.eql(1);
},
4,
2000
);
await retry.waitForWithTimeout('reported events to be stored into ES', 8000, async () => {
const savedObjects = await fetchUsageCountersObjects();
const countTypeEvent = getCounterById(
savedObjects,
`uiCounter:${dayDate}:${METRIC_TYPE.COUNT}:myApp:${uniqueEventName}`
);
expect(countTypeEvent.attributes.count).to.eql(1);

const clickTypeEvent = getCounterById(
savedObjects,
`uiCounter:${dayDate}:${METRIC_TYPE.CLICK}:myApp:${uniqueEventName}`
);
expect(clickTypeEvent.attributes.count).to.eql(2);

const secondEvent = getCounterById(
savedObjects,
`uiCounter:${dayDate}:${METRIC_TYPE.COUNT}:myApp:${uniqueEventName}_2`
);
expect(secondEvent.attributes.count).to.eql(1);
return true;
});
});
});
}

0 comments on commit 2e8d126

Please sign in to comment.