From 5dca95220f72b2286efd5a2f976f5399a3f02059 Mon Sep 17 00:00:00 2001 From: Ryland Herrick Date: Fri, 17 Apr 2020 14:33:14 -0500 Subject: [PATCH 1/2] Increase time between creating a rule and retrieving its status We need to wait for ES to become consistent. --- .../security_and_spaces/tests/find_statuses.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses.ts b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses.ts index 07f3a34d6ff44..1ba19a2b48e6e 100644 --- a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses.ts +++ b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses.ts @@ -50,7 +50,7 @@ export default ({ getService }: FtrProviderContext): void => { .send(getSimpleRule()) .expect(200); - await new Promise(resolve => setTimeout(resolve, 1000)).then(async () => { + await new Promise(resolve => setTimeout(resolve, 5000)).then(async () => { // query the single rule from _find const { body } = await supertest .post(`${DETECTION_ENGINE_RULES_URL}/_find_statuses`) From 1ce95d9545fa827fc8d9abd95288da490dbb2ddf Mon Sep 17 00:00:00 2001 From: Ryland Herrick Date: Fri, 17 Apr 2020 14:35:37 -0500 Subject: [PATCH 2/2] Prefer sequential `await`s to .then() --- .../tests/find_statuses.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses.ts b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses.ts index 1ba19a2b48e6e..44847d5c8146c 100644 --- a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses.ts +++ b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses.ts @@ -50,17 +50,18 @@ export default ({ getService }: FtrProviderContext): void => { .send(getSimpleRule()) .expect(200); - await new Promise(resolve => setTimeout(resolve, 5000)).then(async () => { - // query the single rule from _find - const { body } = await supertest - .post(`${DETECTION_ENGINE_RULES_URL}/_find_statuses`) - .set('kbn-xsrf', 'true') - .send({ ids: [resBody.id] }) - .expect(200); + // wait for Task Manager to execute the rule and update status + await new Promise(resolve => setTimeout(resolve, 5000)); - // expected result for status should be 'going to run' or 'succeeded - expect(['succeeded', 'going to run']).to.contain(body[resBody.id].current_status.status); - }); + // query the single rule from _find + const { body } = await supertest + .post(`${DETECTION_ENGINE_RULES_URL}/_find_statuses`) + .set('kbn-xsrf', 'true') + .send({ ids: [resBody.id] }) + .expect(200); + + // expected result for status should be 'going to run' or 'succeeded + expect(['succeeded', 'going to run']).to.contain(body[resBody.id].current_status.status); }); }); };