Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security_Solution] Remove Flaky Tests #69597

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 0 additions & 176 deletions x-pack/test/api_integration/apis/endpoint/alerts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
import expect from '@kbn/expect/expect.js';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { AlertData } from '../../../../../plugins/security_solution/common/endpoint_alerts/types';
import { eventsIndexPattern } from '../../../../../plugins/security_solution/common/endpoint/constants';
import {
deleteEventsStream,
deleteMetadataStream,
Expand All @@ -26,46 +24,8 @@ const numberOfAlertsInFixture = numberOfHosts * numberOfAlertsPerHost;
*/
const defaultPageSize = 10;

/**
* `NULLABLE_EVENT_FIELD` should be a field in the fixture that exists for some alerts,
* but not all.
*
* This allows us to test sorting and paging on mixed data that may or may not exist
* for each alert.
*/
const NULLABLE_EVENT_FIELD = 'process.parent.entity_id';

/**
* An Elasticsearch query to get the alert (or alerts) without `NULLABLE_EVENT_FIELD`.
*/
const ES_QUERY_MISSING = {
query: {
bool: {
must: [
{
bool: {
must_not: {
exists: {
field: NULLABLE_EVENT_FIELD,
},
},
},
},
{
term: {
'event.kind': {
value: 'alert',
},
},
},
],
},
},
};

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const es = getService('legacyEs');
const client = getService('es');
const nextPrevPrefixQuery = "query=(language:kuery,query:'')";
const nextPrevPrefixDateRange = "date_range=(from:'2018-01-10T00:00:00.000Z',to:now)";
Expand All @@ -74,8 +34,6 @@ export default function ({ getService }: FtrProviderContext) {
const nextPrevPrefixPageSize = 'page_size=10';
const nextPrevPrefix = `${nextPrevPrefixQuery}&${nextPrevPrefixDateRange}&${nextPrevPrefixSort}&${nextPrevPrefixOrder}&${nextPrevPrefixPageSize}`;

let nullableEventId = '';

describe('Endpoint alert API', () => {
describe('when data is in elasticsearch', () => {
before(async () => {
Expand All @@ -89,12 +47,6 @@ export default function ({ getService }: FtrProviderContext) {
'events-endpoint-1',
numberOfAlertsPerHost
);

const res = await es.search({
index: eventsIndexPattern,
body: ES_QUERY_MISSING,
});
nullableEventId = res.hits.hits[0]._source.event.id;
});

after(async () => {
Expand Down Expand Up @@ -260,134 +212,6 @@ export default function ({ getService }: FtrProviderContext) {
expect(emptyBody.alerts.length).to.eql(0);
});

it('alerts api should return data using `before` by custom sort parameter, descending', async () => {
const { body } = await supertest
.get(
`/api/endpoint/alerts?${nextPrevPrefixDateRange}&${nextPrevPrefixPageSize}&${nextPrevPrefixOrder}&sort=process.name&before=malware%20writer&before=4d7afd81-26ec-47c0-9741-ae16d331f73d`
)
.set('kbn-xsrf', 'xxx')
.expect(200);
let valid: boolean = true;
(body.alerts as AlertData[]).forEach((alert) => {
if (alert.process?.name > 'malware writer') {
valid = false;
}
});
expect(valid).to.eql(true);
});

it('alerts api should return data using `before` on undefined primary sort values by custom sort parameter, descending', async () => {
const { body } = await supertest
.get(
`/api/endpoint/alerts?${nextPrevPrefixDateRange}&${nextPrevPrefixPageSize}&order=desc&sort=${NULLABLE_EVENT_FIELD}&before=&before=${nullableEventId}&empty_string_is_undefined=true`
)
.set('kbn-xsrf', 'xxx')
.expect(200);

let lastSeen: string | undefined = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
let valid: boolean = true;

for (const alert of body.alerts) {
const entityId = alert.process?.parent?.entity_id;
if (entityId === undefined && alert.event.id > nullableEventId) {
valid = false;
}
if (entityId !== undefined && lastSeen !== undefined && entityId > lastSeen) {
valid = false;
} else {
lastSeen = entityId;
}
}

expect(valid).to.eql(true);
});

it('alerts api should return data using `before` on undefined primary sort values by custom sort parameter, ascending', async () => {
const { body } = await supertest
.get(
`/api/endpoint/alerts?${nextPrevPrefixDateRange}&page_size=25&order=asc&sort=${NULLABLE_EVENT_FIELD}&before=&before=${nullableEventId}&empty_string_is_undefined=true`
)
.set('kbn-xsrf', 'xxx')
.expect(200);

let lastSeen: string | undefined = '1';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which tests are flaky? I'm only seeing one failure which is consistent in this test and can be fixed by changing this from = '1' to = undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other tests I'm removing have uuids in the URL and I'm not seeing where we're pinning the seed for generator so those could probably fail too.

Copy link
Contributor

@marshallmain marshallmain Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I missed that, well if we want to fix and add back that's fine.

let valid: boolean = true;

for (const alert of body.alerts) {
const entityId = alert.process?.parent?.entity_id;
if (entityId === undefined && alert.event.id < nullableEventId) {
valid = false;
}
if (entityId !== undefined && lastSeen !== undefined && entityId < lastSeen) {
valid = false;
} else {
lastSeen = entityId;
}
}
expect(valid).to.eql(true);
});

it('should return data using `after` by custom sort parameter, descending', async () => {
const { body } = await supertest
.get(
`/api/endpoint/alerts?${nextPrevPrefixDateRange}&${nextPrevPrefixPageSize}&${nextPrevPrefixOrder}&sort=process.pid&after=3&after=66008e21-2493-4b15-a937-939ea228064a`
)
.set('kbn-xsrf', 'xxx')
.expect(200);
expect(body.alerts.length).to.eql(10);
expect(body.alerts[0].process.pid).to.eql(2);
});

it('alerts api should return data using `after` on undefined primary sort values by custom sort parameter, descending', async () => {
const { body } = await supertest
.get(
`/api/endpoint/alerts?${nextPrevPrefixDateRange}&${nextPrevPrefixPageSize}&sort=${NULLABLE_EVENT_FIELD}&order=desc&after=&after=${nullableEventId}&empty_string_is_undefined=true`
)
.set('kbn-xsrf', 'xxx')
.expect(200);

let lastSeen: string | undefined = 'zzzzzzzzzzzzzzzzzzzzzzzzzzz';
let valid: boolean = true;

for (const alert of body.alerts) {
const entityId = alert.process?.parent?.entity_id;
if (entityId === undefined && alert.event.id < nullableEventId) {
valid = false;
}
if (entityId !== undefined && lastSeen !== undefined && entityId > lastSeen) {
valid = false;
} else {
lastSeen = entityId;
}
}
expect(valid).to.eql(true);
});

it('alerts api should return data using `after` on undefined primary sort values by custom sort parameter, ascending', async () => {
const { body } = await supertest
.get(
`/api/endpoint/alerts?${nextPrevPrefixDateRange}&${nextPrevPrefixPageSize}&sort=${NULLABLE_EVENT_FIELD}&order=asc&after=&after=${nullableEventId}&empty_string_is_undefined=true`
)
.set('kbn-xsrf', 'xxx')
.expect(200);

let lastSeen: string | undefined = '1';
let valid: boolean = true;

for (const alert of body.alerts) {
const entityId = alert.process?.parent?.entity_id;
if (entityId === undefined && alert.event.id < nullableEventId) {
valid = false;
}
if (entityId !== undefined && lastSeen !== undefined && entityId < lastSeen) {
valid = false;
} else {
lastSeen = entityId;
}
}
expect(valid).to.eql(true);
});

it('should filter results of alert data using rison-encoded filters', async () => {
const { body: firstBody } = await supertest
.get('/api/endpoint/alerts?page_index=0')
Expand Down