From f0d84409f44e5a87d200160bf7c4eb575a05638d Mon Sep 17 00:00:00 2001 From: Yara Tercero Date: Tue, 20 Oct 2020 16:22:47 -0400 Subject: [PATCH 1/2] fix flakey test --- .../public/common/hooks/eql/helpers.test.ts | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/hooks/eql/helpers.test.ts b/x-pack/plugins/security_solution/public/common/hooks/eql/helpers.test.ts index 52804c0b17e75..644939f7e768c 100644 --- a/x-pack/plugins/security_solution/public/common/hooks/eql/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/common/hooks/eql/helpers.test.ts @@ -3,7 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import dateMath from '@elastic/datemath'; import moment from 'moment'; import { EqlSearchStrategyResponse } from '../../../../../data_enhanced/common'; @@ -26,8 +25,8 @@ describe('eql/helpers', () => { describe('calculateBucketForHour', () => { test('returns 2 if event occurred within 2 minutes of "now"', () => { const diff = calculateBucketForHour( - Number(dateMath.parse('now-1m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T05:56:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(2); @@ -35,8 +34,8 @@ describe('eql/helpers', () => { test('returns 10 if event occurred within 8-10 minutes of "now"', () => { const diff = calculateBucketForHour( - Number(dateMath.parse('now-9m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T05:48:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(10); @@ -44,8 +43,8 @@ describe('eql/helpers', () => { test('returns 16 if event occurred within 10-15 minutes of "now"', () => { const diff = calculateBucketForHour( - Number(dateMath.parse('now-15m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T05:42:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(16); @@ -53,8 +52,8 @@ describe('eql/helpers', () => { test('returns 60 if event occurred within 58-60 minutes of "now"', () => { const diff = calculateBucketForHour( - Number(dateMath.parse('now-59m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T04:58:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(60); @@ -62,8 +61,8 @@ describe('eql/helpers', () => { test('returns exact time difference if it is a multiple of 2', () => { const diff = calculateBucketForHour( - Number(dateMath.parse('now-20m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T05:37:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(20); @@ -71,8 +70,8 @@ describe('eql/helpers', () => { test('returns 0 if times are equal', () => { const diff = calculateBucketForHour( - Number(dateMath.parse('now')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T05:57:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(0); @@ -80,8 +79,8 @@ describe('eql/helpers', () => { test('returns 2 if event occurred within 2 minutes of "now" but arguments are flipped', () => { const diff = calculateBucketForHour( - Number(dateMath.parse('now')?.format('x')), - Number(dateMath.parse('now-1m')?.format('x')) + Date.parse('2020-02-20T05:57:54.037Z'), + Date.parse('2020-02-20T05:56:54.037Z') ); expect(diff).toEqual(2); @@ -91,8 +90,8 @@ describe('eql/helpers', () => { describe('calculateBucketForDay', () => { test('returns 0 if two dates are equivalent', () => { const diff = calculateBucketForDay( - Number(dateMath.parse('now')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T05:57:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(0); @@ -100,8 +99,8 @@ describe('eql/helpers', () => { test('returns 1 if event occurred within 60 minutes of "now"', () => { const diff = calculateBucketForDay( - Number(dateMath.parse('now-40m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T05:17:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(1); @@ -109,8 +108,8 @@ describe('eql/helpers', () => { test('returns 2 if event occurred 60-120 minutes from "now"', () => { const diff = calculateBucketForDay( - Number(dateMath.parse('now-120m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T03:57:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(2); @@ -118,8 +117,8 @@ describe('eql/helpers', () => { test('returns 3 if event occurred 120-180 minutes from "now', () => { const diff = calculateBucketForDay( - Number(dateMath.parse('now-121m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T03:56:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(3); @@ -127,8 +126,8 @@ describe('eql/helpers', () => { test('returns 4 if event occurred 180-240 minutes from "now', () => { const diff = calculateBucketForDay( - Number(dateMath.parse('now-220m')?.format('x')), - Number(dateMath.parse('now')?.format('x')) + Date.parse('2020-02-20T02:15:54.037Z'), + Date.parse('2020-02-20T05:57:54.037Z') ); expect(diff).toEqual(4); @@ -136,8 +135,8 @@ describe('eql/helpers', () => { test('returns 2 if event occurred 60-120 minutes of "now" but arguments are flipped', () => { const diff = calculateBucketForDay( - Number(dateMath.parse('now')?.format('x')), - Number(dateMath.parse('now-118m')?.format('x')) + Date.parse('2020-02-20T05:57:54.037Z'), + Date.parse('2020-02-20T03:59:54.037Z') ); expect(diff).toEqual(2); From 7714dc16b1df866680bbcf637bc15e5a83f5f26a Mon Sep 17 00:00:00 2001 From: Yara Tercero Date: Tue, 20 Oct 2020 17:27:55 -0400 Subject: [PATCH 2/2] fix test descriptions --- .../public/common/hooks/eql/helpers.test.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/hooks/eql/helpers.test.ts b/x-pack/plugins/security_solution/public/common/hooks/eql/helpers.test.ts index 644939f7e768c..6ba2eaa3d3c30 100644 --- a/x-pack/plugins/security_solution/public/common/hooks/eql/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/common/hooks/eql/helpers.test.ts @@ -23,7 +23,7 @@ import { getMockEqlResponse, getMockEqlSequenceResponse } from './eql_search_res describe('eql/helpers', () => { describe('calculateBucketForHour', () => { - test('returns 2 if event occurred within 2 minutes of "now"', () => { + test('returns 2 if the difference in times is 2 minutes', () => { const diff = calculateBucketForHour( Date.parse('2020-02-20T05:56:54.037Z'), Date.parse('2020-02-20T05:57:54.037Z') @@ -32,7 +32,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(2); }); - test('returns 10 if event occurred within 8-10 minutes of "now"', () => { + test('returns 10 if the difference in times is 8-10 minutes', () => { const diff = calculateBucketForHour( Date.parse('2020-02-20T05:48:54.037Z'), Date.parse('2020-02-20T05:57:54.037Z') @@ -41,7 +41,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(10); }); - test('returns 16 if event occurred within 10-15 minutes of "now"', () => { + test('returns 16 if the difference in times is 10-15 minutes', () => { const diff = calculateBucketForHour( Date.parse('2020-02-20T05:42:54.037Z'), Date.parse('2020-02-20T05:57:54.037Z') @@ -50,7 +50,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(16); }); - test('returns 60 if event occurred within 58-60 minutes of "now"', () => { + test('returns 60 if the difference in times is 58-60 minutes', () => { const diff = calculateBucketForHour( Date.parse('2020-02-20T04:58:54.037Z'), Date.parse('2020-02-20T05:57:54.037Z') @@ -77,7 +77,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(0); }); - test('returns 2 if event occurred within 2 minutes of "now" but arguments are flipped', () => { + test('returns 2 if the difference in times is 2 minutes but arguments are flipped', () => { const diff = calculateBucketForHour( Date.parse('2020-02-20T05:57:54.037Z'), Date.parse('2020-02-20T05:56:54.037Z') @@ -97,7 +97,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(0); }); - test('returns 1 if event occurred within 60 minutes of "now"', () => { + test('returns 1 if the difference in times is 60 minutes', () => { const diff = calculateBucketForDay( Date.parse('2020-02-20T05:17:54.037Z'), Date.parse('2020-02-20T05:57:54.037Z') @@ -106,7 +106,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(1); }); - test('returns 2 if event occurred 60-120 minutes from "now"', () => { + test('returns 2 if the difference in times is 60-120 minutes', () => { const diff = calculateBucketForDay( Date.parse('2020-02-20T03:57:54.037Z'), Date.parse('2020-02-20T05:57:54.037Z') @@ -115,7 +115,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(2); }); - test('returns 3 if event occurred 120-180 minutes from "now', () => { + test('returns 3 if the difference in times is 120-180 minutes', () => { const diff = calculateBucketForDay( Date.parse('2020-02-20T03:56:54.037Z'), Date.parse('2020-02-20T05:57:54.037Z') @@ -124,7 +124,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(3); }); - test('returns 4 if event occurred 180-240 minutes from "now', () => { + test('returns 4 if the difference in times is 180-240 minutes', () => { const diff = calculateBucketForDay( Date.parse('2020-02-20T02:15:54.037Z'), Date.parse('2020-02-20T05:57:54.037Z') @@ -133,7 +133,7 @@ describe('eql/helpers', () => { expect(diff).toEqual(4); }); - test('returns 2 if event occurred 60-120 minutes of "now" but arguments are flipped', () => { + test('returns 2 if the difference in times is 60-120 minutes but arguments are flipped', () => { const diff = calculateBucketForDay( Date.parse('2020-02-20T05:57:54.037Z'), Date.parse('2020-02-20T03:59:54.037Z')