From 4e9e2c634ea355fa7764cff01912541532bfcd60 Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Mon, 26 Nov 2018 11:46:19 -0800 Subject: [PATCH 1/6] Removes event-stream package (and sub-deps) + implements a similar API to what we were using --- package.json | 1 - .../reload_logging_config.test.js | 9 +-- src/dev/failed_tests/report.js | 8 +-- src/utils/streams/array_stream.js | 55 +++++++++++++++++++ yarn.lock | 23 +++++++- 5 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 src/utils/streams/array_stream.js diff --git a/package.json b/package.json index a982137a2d9d8..e696c06b6353f 100644 --- a/package.json +++ b/package.json @@ -317,7 +317,6 @@ "eslint-plugin-prefer-object-spread": "^1.2.1", "eslint-plugin-prettier": "^2.6.2", "eslint-plugin-react": "^7.11.1", - "event-stream": "3.3.2", "expect.js": "0.3.1", "faker": "1.1.0", "fetch-mock": "^5.13.1", diff --git a/src/cli/serve/integration_tests/reload_logging_config.test.js b/src/cli/serve/integration_tests/reload_logging_config.test.js index e80a3d9d4fb81..0680157504533 100644 --- a/src/cli/serve/integration_tests/reload_logging_config.test.js +++ b/src/cli/serve/integration_tests/reload_logging_config.test.js @@ -21,7 +21,7 @@ import { spawn } from 'child_process'; import { writeFileSync } from 'fs'; import { relative, resolve } from 'path'; import { safeDump } from 'js-yaml'; -import es from 'event-stream'; +import { split, map } from '../../../utils/streams/array_stream'; import { getConfigFromFiles } from '../../../core/server/config/read_config'; const testConfigFile = follow('__fixtures__/reload_logging_config/kibana.test.yml'); @@ -88,11 +88,11 @@ describe('Server logging configuration', function () { }); child.stdout - .pipe(es.split()) - .pipe(es.mapSync(line => { + .pipe(split()) + .pipe(map((line, callback) => { if (!line) { // skip empty lines - return; + return callback(); } if (isJson) { @@ -113,6 +113,7 @@ describe('Server logging configuration', function () { child.kill(); child = undefined; } + callback(); })); function switchToPlainTextLog() { diff --git a/src/dev/failed_tests/report.js b/src/dev/failed_tests/report.js index 9a9c7acdfd270..f724192744c8e 100644 --- a/src/dev/failed_tests/report.js +++ b/src/dev/failed_tests/report.js @@ -19,7 +19,7 @@ import xml2js from 'xml2js'; import vfs from 'vinyl-fs'; -import es from 'event-stream'; +import { map } from '../../utils/streams/array_stream'; import { getGithubClient, markdownMetadata, paginate } from '../github_utils'; import { find } from 'lodash'; import stripAnsi from 'strip-ansi'; @@ -32,7 +32,7 @@ const BUILD_URL = process.env.BUILD_URL; /** * Parses junit XML files into JSON */ -const mapXml = es.map((file, cb) => { +const mapXml = map((file, cb) => { xml2js.parseString(file.contents.toString(), (err, result) => { cb(null, result); }); @@ -41,7 +41,7 @@ const mapXml = es.map((file, cb) => { /** * Filters all testsuites to find failed testcases */ -const filterFailures = es.map((testSuite, cb) => { +const filterFailures = map((testSuite, cb) => { // Grab the failures. Reporters may report multiple testsuites in a single file. const testFiles = testSuite.testsuites ? testSuite.testsuites.testsuite @@ -71,7 +71,7 @@ const filterFailures = es.map((testSuite, cb) => { * Creates and updates github issues for the given testcase failures. */ const updateGithubIssues = (githubClient, issues) => { - return es.map(async (failureCases, cb) => { + return map(async (failureCases, cb) => { const issueOps = failureCases.map(async (failureCase) => { const existingIssue = find(issues, (issue) => { diff --git a/src/utils/streams/array_stream.js b/src/utils/streams/array_stream.js new file mode 100644 index 0000000000000..8c872d4a2e379 --- /dev/null +++ b/src/utils/streams/array_stream.js @@ -0,0 +1,55 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Duplex } from 'stream'; +const NEWLINE_REGEX = /\r?\n/; + +export function map(mapfn) { + const stream = new Duplex({ + write(chunk, _encoding, callback) { + // TS doesn't like `push` on this... + this.push(mapfn(chunk, callback)); + }, + read() {} + }); + + return stream; +} + +export function split() { + const stream = new Duplex({ + write(chunk, _encoding, callback) { + this.buffer = (this.buffer || '') + chunk.toString(); + + if (NEWLINE_REGEX.test(chunk.toString())) { + const splitChunks = this.buffer.split(NEWLINE_REGEX); + + splitChunks.forEach((chunk) => { + this.push(chunk); + }); + + this.buffer = splitChunks[splitChunks.length - 1]; + } + callback(); + }, + read() {} + }); + + return stream; +} diff --git a/yarn.lock b/yarn.lock index b921e9e93bccf..b0666713bd93c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7063,7 +7063,7 @@ duplexer3@^0.1.4: resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" integrity sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI= -duplexer@^0.1.1, duplexer@~0.1.1: +duplexer@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1" integrity sha1-rOb/gIwc5mtX0ev5eXessCM0z8E= @@ -7929,6 +7929,7 @@ event-emitter@~0.3.5: d "1" es5-ext "~0.10.14" +<<<<<<< HEAD event-stream@3.3.2: version "3.3.2" resolved "http://registry.npmjs.org/event-stream/-/event-stream-3.3.2.tgz#3cc310feb1f28d2f62b2a085d736a9ef566378b8" @@ -7942,6 +7943,8 @@ event-stream@3.3.2: stream-combiner "~0.0.4" through "~2.3.1" +======= +>>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using eventemitter2@~0.4.13: version "0.4.14" resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-0.4.14.tgz#8f61b75cde012b2e9eb284d4545583b5643b61ab" @@ -8921,7 +8924,11 @@ from2@^2.1.0, from2@^2.1.1: inherits "^2.0.1" readable-stream "^2.0.0" +<<<<<<< HEAD from@^0.1.3, from@~0: +======= +from@^0.1.3: +>>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using version "0.1.7" resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe" integrity sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4= @@ -13829,11 +13836,14 @@ map-obj@^2.0.0: resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-2.0.0.tgz#a65cd29087a92598b8791257a523e021222ac1f9" integrity sha1-plzSkIepJZi4eRJXpSPgISIqwfk= +<<<<<<< HEAD map-stream@~0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194" integrity sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ= +======= +>>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using map-visit@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f" @@ -15871,6 +15881,7 @@ path-type@^2.0.0: dependencies: pify "^2.0.0" +<<<<<<< HEAD pause-stream@0.0.11: version "0.0.11" resolved "https://registry.yarnpkg.com/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445" @@ -15878,6 +15889,8 @@ pause-stream@0.0.11: dependencies: through "~2.3" +======= +>>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using pbkdf2@^3.0.3: version "3.0.14" resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.14.tgz#a35e13c64799b06ce15320f459c230e68e73bade" @@ -19559,6 +19572,7 @@ split-string@^3.0.1, split-string@^3.0.2: dependencies: extend-shallow "^3.0.0" +<<<<<<< HEAD split@0.3: version "0.3.3" resolved "https://registry.yarnpkg.com/split/-/split-0.3.3.tgz#cd0eea5e63a211dfff7eb0f091c4133e2d0dd28f" @@ -19566,6 +19580,8 @@ split@0.3: dependencies: through "2" +======= +>>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using sprintf-js@^1.0.3: version "1.1.1" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.1.tgz#36be78320afe5801f6cea3ee78b6e5aab940ea0c" @@ -19692,6 +19708,7 @@ stream-browserify@^2.0.1: inherits "~2.0.1" readable-stream "^2.0.2" +<<<<<<< HEAD stream-combiner@~0.0.4: version "0.0.4" resolved "https://registry.yarnpkg.com/stream-combiner/-/stream-combiner-0.0.4.tgz#4d5e433c185261dde623ca3f44c586bcf5c4ad14" @@ -19699,6 +19716,8 @@ stream-combiner@~0.0.4: dependencies: duplexer "~0.1.1" +======= +>>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using stream-consume@~0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/stream-consume/-/stream-consume-0.1.0.tgz#a41ead1a6d6081ceb79f65b061901b6d8f3d1d0f" @@ -20395,7 +20414,7 @@ through2@~0.4.1: readable-stream "~1.0.17" xtend "~2.1.1" -through@2, "through@>=2.2.7 <3", through@^2.3.4, through@^2.3.6, through@^2.3.8, through@~2.3, through@~2.3.1, through@~2.3.4, through@~2.3.6: +"through@>=2.2.7 <3", through@^2.3.4, through@^2.3.6, through@^2.3.8, through@~2.3.4, through@~2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= From 31a7fe97089eeef01d87a3d45cfb0a557a52cd52 Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Mon, 26 Nov 2018 14:33:37 -0800 Subject: [PATCH 2/6] Removing array_streams in favor of existing utils --- .../reload_logging_config.test.js | 9 ++- src/dev/failed_tests/report.js | 23 ++++---- src/utils/streams/array_stream.js | 55 ------------------- 3 files changed, 17 insertions(+), 70 deletions(-) delete mode 100644 src/utils/streams/array_stream.js diff --git a/src/cli/serve/integration_tests/reload_logging_config.test.js b/src/cli/serve/integration_tests/reload_logging_config.test.js index 0680157504533..f304a1c3e0a1f 100644 --- a/src/cli/serve/integration_tests/reload_logging_config.test.js +++ b/src/cli/serve/integration_tests/reload_logging_config.test.js @@ -21,7 +21,7 @@ import { spawn } from 'child_process'; import { writeFileSync } from 'fs'; import { relative, resolve } from 'path'; import { safeDump } from 'js-yaml'; -import { split, map } from '../../../utils/streams/array_stream'; +import { createMapStream, createSplitStream } from '../../../utils/streams'; import { getConfigFromFiles } from '../../../core/server/config/read_config'; const testConfigFile = follow('__fixtures__/reload_logging_config/kibana.test.yml'); @@ -88,11 +88,11 @@ describe('Server logging configuration', function () { }); child.stdout - .pipe(split()) - .pipe(map((line, callback) => { + .pipe(createSplitStream('\n')) + .pipe(createMapStream((line) => { if (!line) { // skip empty lines - return callback(); + return; } if (isJson) { @@ -113,7 +113,6 @@ describe('Server logging configuration', function () { child.kill(); child = undefined; } - callback(); })); function switchToPlainTextLog() { diff --git a/src/dev/failed_tests/report.js b/src/dev/failed_tests/report.js index f724192744c8e..5a58d4ff825ea 100644 --- a/src/dev/failed_tests/report.js +++ b/src/dev/failed_tests/report.js @@ -19,7 +19,7 @@ import xml2js from 'xml2js'; import vfs from 'vinyl-fs'; -import { map } from '../../utils/streams/array_stream'; +import { createMapStream } from '../../utils/streams'; import { getGithubClient, markdownMetadata, paginate } from '../github_utils'; import { find } from 'lodash'; import stripAnsi from 'strip-ansi'; @@ -32,16 +32,19 @@ const BUILD_URL = process.env.BUILD_URL; /** * Parses junit XML files into JSON */ -const mapXml = map((file, cb) => { +const mapXml = createMapStream((file) => new Promise((resolve, reject) => { xml2js.parseString(file.contents.toString(), (err, result) => { - cb(null, result); + if (err) { + return reject(err); + } + resolve(result); }); -}); +})); /** * Filters all testsuites to find failed testcases */ -const filterFailures = map((testSuite, cb) => { +const filterFailures = createMapStream((testSuite) => { // Grab the failures. Reporters may report multiple testsuites in a single file. const testFiles = testSuite.testsuites ? testSuite.testsuites.testsuite @@ -64,14 +67,14 @@ const filterFailures = map((testSuite, cb) => { console.log(`Found ${failures.length} test failures`); - cb(null, failures); + return failures; }); /** * Creates and updates github issues for the given testcase failures. */ const updateGithubIssues = (githubClient, issues) => { - return map(async (failureCases, cb) => { + return createMapStream(async (failureCases) => { const issueOps = failureCases.map(async (failureCase) => { const existingIssue = find(issues, (issue) => { @@ -123,10 +126,10 @@ const updateGithubIssues = (githubClient, issues) => { } }); - Promise + return Promise .all(issueOps) - .then(() => cb(null, failureCases)) - .catch(e => cb(e)); + .then(() => failureCases) + .catch(e => e); }); }; diff --git a/src/utils/streams/array_stream.js b/src/utils/streams/array_stream.js deleted file mode 100644 index 8c872d4a2e379..0000000000000 --- a/src/utils/streams/array_stream.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { Duplex } from 'stream'; -const NEWLINE_REGEX = /\r?\n/; - -export function map(mapfn) { - const stream = new Duplex({ - write(chunk, _encoding, callback) { - // TS doesn't like `push` on this... - this.push(mapfn(chunk, callback)); - }, - read() {} - }); - - return stream; -} - -export function split() { - const stream = new Duplex({ - write(chunk, _encoding, callback) { - this.buffer = (this.buffer || '') + chunk.toString(); - - if (NEWLINE_REGEX.test(chunk.toString())) { - const splitChunks = this.buffer.split(NEWLINE_REGEX); - - splitChunks.forEach((chunk) => { - this.push(chunk); - }); - - this.buffer = splitChunks[splitChunks.length - 1]; - } - callback(); - }, - read() {} - }); - - return stream; -} From 89287c177baf26a62600b144a02f11f44a3340b1 Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Mon, 26 Nov 2018 14:42:02 -0800 Subject: [PATCH 3/6] Fixing lockfile --- yarn.lock | 58 ------------------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/yarn.lock b/yarn.lock index b0666713bd93c..ee95f877c920c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7929,22 +7929,6 @@ event-emitter@~0.3.5: d "1" es5-ext "~0.10.14" -<<<<<<< HEAD -event-stream@3.3.2: - version "3.3.2" - resolved "http://registry.npmjs.org/event-stream/-/event-stream-3.3.2.tgz#3cc310feb1f28d2f62b2a085d736a9ef566378b8" - integrity sha1-PMMQ/rHyjS9isqCF1zap71ZjeLg= - dependencies: - duplexer "~0.1.1" - from "~0" - map-stream "~0.1.0" - pause-stream "0.0.11" - split "0.3" - stream-combiner "~0.0.4" - through "~2.3.1" - -======= ->>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using eventemitter2@~0.4.13: version "0.4.14" resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-0.4.14.tgz#8f61b75cde012b2e9eb284d4545583b5643b61ab" @@ -8924,11 +8908,7 @@ from2@^2.1.0, from2@^2.1.1: inherits "^2.0.1" readable-stream "^2.0.0" -<<<<<<< HEAD -from@^0.1.3, from@~0: -======= from@^0.1.3: ->>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using version "0.1.7" resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe" integrity sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4= @@ -13836,14 +13816,6 @@ map-obj@^2.0.0: resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-2.0.0.tgz#a65cd29087a92598b8791257a523e021222ac1f9" integrity sha1-plzSkIepJZi4eRJXpSPgISIqwfk= -<<<<<<< HEAD -map-stream@~0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194" - integrity sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ= - -======= ->>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using map-visit@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f" @@ -15881,16 +15853,6 @@ path-type@^2.0.0: dependencies: pify "^2.0.0" -<<<<<<< HEAD -pause-stream@0.0.11: - version "0.0.11" - resolved "https://registry.yarnpkg.com/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445" - integrity sha1-/lo0sMvOErWqaitAPuLnO2AvFEU= - dependencies: - through "~2.3" - -======= ->>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using pbkdf2@^3.0.3: version "3.0.14" resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.14.tgz#a35e13c64799b06ce15320f459c230e68e73bade" @@ -19572,16 +19534,6 @@ split-string@^3.0.1, split-string@^3.0.2: dependencies: extend-shallow "^3.0.0" -<<<<<<< HEAD -split@0.3: - version "0.3.3" - resolved "https://registry.yarnpkg.com/split/-/split-0.3.3.tgz#cd0eea5e63a211dfff7eb0f091c4133e2d0dd28f" - integrity sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8= - dependencies: - through "2" - -======= ->>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using sprintf-js@^1.0.3: version "1.1.1" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.1.tgz#36be78320afe5801f6cea3ee78b6e5aab940ea0c" @@ -19708,16 +19660,6 @@ stream-browserify@^2.0.1: inherits "~2.0.1" readable-stream "^2.0.2" -<<<<<<< HEAD -stream-combiner@~0.0.4: - version "0.0.4" - resolved "https://registry.yarnpkg.com/stream-combiner/-/stream-combiner-0.0.4.tgz#4d5e433c185261dde623ca3f44c586bcf5c4ad14" - integrity sha1-TV5DPBhSYd3mI8o/RMWGvPXErRQ= - dependencies: - duplexer "~0.1.1" - -======= ->>>>>>> Removes event-stream package (and sub-deps) + implements a similar API to what we were using stream-consume@~0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/stream-consume/-/stream-consume-0.1.0.tgz#a41ead1a6d6081ceb79f65b061901b6d8f3d1d0f" From 1606ebae53d6ff22aa26366d0b0e3dae2e15f359 Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Tue, 27 Nov 2018 08:13:51 -0800 Subject: [PATCH 4/6] Allow report-errors to propogate through (don't catch) --- src/dev/failed_tests/report.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dev/failed_tests/report.js b/src/dev/failed_tests/report.js index 5a58d4ff825ea..6841353aff6a7 100644 --- a/src/dev/failed_tests/report.js +++ b/src/dev/failed_tests/report.js @@ -128,8 +128,7 @@ const updateGithubIssues = (githubClient, issues) => { return Promise .all(issueOps) - .then(() => failureCases) - .catch(e => e); + .then(() => failureCases); }); }; From 21700388a135e6a10f4f1f2f146ad831bbcf8b5a Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 27 Nov 2018 16:40:47 -0800 Subject: [PATCH 5/6] [cli/reloacConfig/test] update test to use promises --- .../reload_logging_config.test.js | 105 +++++++++--------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/src/cli/serve/integration_tests/reload_logging_config.test.js b/src/cli/serve/integration_tests/reload_logging_config.test.js index f304a1c3e0a1f..dd390ecba041b 100644 --- a/src/cli/serve/integration_tests/reload_logging_config.test.js +++ b/src/cli/serve/integration_tests/reload_logging_config.test.js @@ -20,8 +20,9 @@ import { spawn } from 'child_process'; import { writeFileSync } from 'fs'; import { relative, resolve } from 'path'; + import { safeDump } from 'js-yaml'; -import { createMapStream, createSplitStream } from '../../../utils/streams'; +import { createMapStream, createSplitStream, createPromiseFromStreams } from '../../../utils/streams'; import { getConfigFromFiles } from '../../../core/server/config/read_config'; const testConfigFile = follow('__fixtures__/reload_logging_config/kibana.test.yml'); @@ -66,65 +67,67 @@ describe('Server logging configuration', function () { // nothing to do for Windows }); } else { - it('should be reloadable via SIGHUP process signaling', function (done) { + it('should be reloadable via SIGHUP process signaling', async function () { expect.assertions(3); - child = spawn('node', [kibanaPath, '--config', testConfigFile]); - - child.on('error', err => { - done(new Error(`error in child process while attempting to reload config. ${err.stack || err.message || err}`)); + child = spawn(process.execPath, [kibanaPath, '--config', testConfigFile], { + stdio: 'pipe' }); let sawJson = false; let sawNonjson = false; - child.on('exit', _code => { - const code = _code === null ? 0 : _code; - - expect(code).toEqual(0); - expect(sawJson).toEqual(true); - expect(sawNonjson).toEqual(true); - done(); - }); - - child.stdout - .pipe(createSplitStream('\n')) - .pipe(createMapStream((line) => { - if (!line) { - // skip empty lines - return; - } - - if (isJson) { - const data = JSON.parse(line); - sawJson = true; + const [exitCode] = await Promise.all([ + Promise.race([ + new Promise(r => child.once('exit', r)) + .then(code => code === null ? 0 : code), + + new Promise(r => child.once('error', r)) + .then(err => { + throw new Error(`error in child process while attempting to reload config. ${err.stack || err.message || err}`); + }) + ]), + + createPromiseFromStreams([ + child.stdout, + createSplitStream('\n'), + createMapStream(async (line) => { + if (!line) { + // skip empty lines + return; + } - if (data.tags.includes('listening')) { - switchToPlainTextLog(); + if (isJson) { + const data = JSON.parse(line); + sawJson = true; + + if (data.tags.includes('listening')) { + isJson = false; + setLoggingJson(false); + + // Reload logging config. We give it a little bit of time to just make + // sure the process sighup handler is registered. + await new Promise(r => setTimeout(r, 100)); + child.kill('SIGHUP'); + } + } else if (line.startsWith('{')) { + // We have told Kibana to stop logging json, but it hasn't completed + // the switch yet, so we ignore before switching over. + } else { + // Kibana has successfully stopped logging json, so kill the server. + + sawNonjson = true; + + child.kill(); + child = undefined; } - } else if (line.startsWith('{')) { - // We have told Kibana to stop logging json, but it hasn't completed - // the switch yet, so we ignore before switching over. - } else { - // Kibana has successfully stopped logging json, so kill the server. - - sawNonjson = true; - - child.kill(); - child = undefined; - } - })); - - function switchToPlainTextLog() { - isJson = false; - setLoggingJson(false); - - // Reload logging config. We give it a little bit of time to just make - // sure the process sighup handler is registered. - setTimeout(() => { - child.kill('SIGHUP'); - }, 100); - } + }) + ]) + ]); + + expect(exitCode).toEqual(0); + expect(sawJson).toEqual(true); + expect(sawNonjson).toEqual(true); }, 60000); } }); From b60f29617a71082291976fca798dc1ef868ead13 Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 27 Nov 2018 17:18:25 -0800 Subject: [PATCH 6/6] avoid mixing async and Promise.then more than necessary --- src/dev/failed_tests/report.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/dev/failed_tests/report.js b/src/dev/failed_tests/report.js index 6841353aff6a7..7eadfccf91344 100644 --- a/src/dev/failed_tests/report.js +++ b/src/dev/failed_tests/report.js @@ -76,7 +76,7 @@ const filterFailures = createMapStream((testSuite) => { const updateGithubIssues = (githubClient, issues) => { return createMapStream(async (failureCases) => { - const issueOps = failureCases.map(async (failureCase) => { + await Promise.all(failureCases.map(async (failureCase) => { const existingIssue = find(issues, (issue) => { return markdownMetadata.get(issue.body, 'test.class') === failureCase.classname && markdownMetadata.get(issue.body, 'test.name') === failureCase.name; @@ -124,11 +124,9 @@ const updateGithubIssues = (githubClient, issues) => { console.log(`Created issue ${newIssue.data.html_url}`); } - }); + })); - return Promise - .all(issueOps) - .then(() => failureCases); + return failureCases; }); };