Skip to content

Commit

Permalink
fix flaky test (#119713)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic authored Nov 25, 2021
1 parent 37b9fce commit 905d6b5
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions x-pack/plugins/fleet/server/telemetry/sender.test.ts
Original file line number Diff line number Diff line change
@@ -32,6 +32,15 @@ describe('TelemetryEventsSender', () => {
beforeEach(() => {
logger = loggingSystemMock.createLogger();
sender = new TelemetryEventsSender(logger);
sender['fetchClusterInfo'] = jest.fn(async () => {
return {
cluster_uuid: '1',
cluster_name: 'name',
version: {
number: '8.0.0',
},
} as InfoResponse;
});
sender.start(undefined, {
elasticsearch: { client: { asInternalUser: { info: jest.fn(async () => ({})) } } },
} as any);
@@ -76,7 +85,7 @@ describe('TelemetryEventsSender', () => {

expect(sender['sendEvents']).toHaveBeenCalledWith(
'https://telemetry-staging.elastic.co/v3/send/fleet-upgrades',
undefined,
{ cluster_name: 'name', cluster_uuid: '1', version: { number: '8.0.0' } },
expect.anything()
);
});
@@ -113,16 +122,6 @@ describe('TelemetryEventsSender', () => {
),
};

sender['fetchClusterInfo'] = jest.fn(async () => {
return {
cluster_uuid: '1',
cluster_name: 'name',
version: {
number: '8.0.0',
},
} as InfoResponse;
});

const myChannelEvents = [{ 'event.kind': '1' }, { 'event.kind': '2' }];
// @ts-ignore
sender.queueTelemetryEvents('my-channel', myChannelEvents);
6 changes: 3 additions & 3 deletions x-pack/plugins/fleet/server/telemetry/sender.ts
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ export class TelemetryEventsSender {
private queuesPerChannel: { [channel: string]: TelemetryQueue<any> } = {};
private isOptedIn?: boolean = true; // Assume true until the first check
private esClient?: ElasticsearchClient;
private clusterInfo?: InfoResponse;

constructor(logger: Logger) {
this.logger = logger;
@@ -46,6 +47,7 @@ export class TelemetryEventsSender {
public async start(telemetryStart?: TelemetryPluginStart, core?: CoreStart) {
this.telemetryStart = telemetryStart;
this.esClient = core?.elasticsearch.client.asInternalUser;
this.clusterInfo = await this.fetchClusterInfo();

this.logger.debug(`Starting local task`);
setTimeout(() => {
@@ -92,12 +94,10 @@ export class TelemetryEventsSender {
return;
}

const clusterInfo = await this.fetchClusterInfo();

for (const channel of Object.keys(this.queuesPerChannel)) {
await this.sendEvents(
await this.fetchTelemetryUrl(channel),
clusterInfo,
this.clusterInfo,
this.queuesPerChannel[channel]
);
}

0 comments on commit 905d6b5

Please sign in to comment.