diff --git a/packages/kbn-es-archiver/src/actions/rebuild_all.ts b/packages/kbn-es-archiver/src/actions/rebuild_all.ts index 1581ff41b95fc..e921e9a23c25e 100644 --- a/packages/kbn-es-archiver/src/actions/rebuild_all.ts +++ b/packages/kbn-es-archiver/src/actions/rebuild_all.ts @@ -7,9 +7,9 @@ */ import { resolve, dirname, relative } from 'path'; -import { stat, Stats, rename, createReadStream, createWriteStream } from 'fs'; +import { createReadStream, createWriteStream } from 'fs'; +import { stat, rename } from 'fs/promises'; import { Readable, Writable } from 'stream'; -import { fromNode } from 'bluebird'; import { ToolingLog } from '@kbn/dev-utils'; import { createPromiseFromStreams } from '@kbn/utils'; import { @@ -21,8 +21,8 @@ import { } from '../lib'; async function isDirectory(path: string): Promise { - const stats: Stats = await fromNode((cb) => stat(path, cb)); - return stats.isDirectory(); + const pathStats = await stat(path); + return pathStats.isDirectory(); } export async function rebuildAllAction({ @@ -59,7 +59,7 @@ export async function rebuildAllAction({ createWriteStream(tempFile), ] as [Readable, ...Writable[]]); - await fromNode((cb) => rename(tempFile, childPath, cb)); + await rename(tempFile, childPath); log.info(`${archiveName} Rebuilt ${childName}`); } } diff --git a/packages/kbn-es-archiver/src/lib/directory.ts b/packages/kbn-es-archiver/src/lib/directory.ts index f82e59a0ed252..dc39a646fc3bf 100644 --- a/packages/kbn-es-archiver/src/lib/directory.ts +++ b/packages/kbn-es-archiver/src/lib/directory.ts @@ -6,10 +6,9 @@ * Side Public License, v 1. */ -import { readdir } from 'fs'; -import { fromNode } from 'bluebird'; +import { readdir } from 'fs/promises'; export async function readDirectory(path: string) { - const allNames = await fromNode((cb) => readdir(path, cb)); + const allNames: string[] = await readdir(path); return allNames.filter((name) => !name.startsWith('.')); } diff --git a/packages/kbn-test/src/functional_tests/lib/auth.js b/packages/kbn-test/src/functional_tests/lib/auth.js index 22c84cd7d13d9..abc2bdd7ae10b 100644 --- a/packages/kbn-test/src/functional_tests/lib/auth.js +++ b/packages/kbn-test/src/functional_tests/lib/auth.js @@ -11,7 +11,7 @@ import util from 'util'; import { format as formatUrl } from 'url'; import request from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; export const DEFAULT_SUPERUSER_PASS = 'changeme'; @@ -56,7 +56,7 @@ async function updateCredentials({ } if (retries > 0) { - await delay(2500); + await timer(2500).toPromise(); return await updateCredentials({ port, auth, @@ -134,7 +134,7 @@ async function insertUser({ } if (retries > 0) { - await delay(2500); + await timer(2500).toPromise(); return await insertUser({ port, auth, diff --git a/packages/kbn-test/src/jest/setup/polyfills.js b/packages/kbn-test/src/jest/setup/polyfills.js index 48b597d280b4a..ebe6178dbdd91 100644 --- a/packages/kbn-test/src/jest/setup/polyfills.js +++ b/packages/kbn-test/src/jest/setup/polyfills.js @@ -6,13 +6,6 @@ * Side Public License, v 1. */ -// bluebird < v3.3.5 does not work with MutationObserver polyfill -// when MutationObserver exists, bluebird avoids using node's builtin async schedulers -const bluebird = require('bluebird'); -bluebird.Promise.setScheduler(function (fn) { - global.setImmediate.call(global, fn); -}); - const MutationObserver = require('mutation-observer'); Object.defineProperty(window, 'MutationObserver', { value: MutationObserver }); diff --git a/packages/kbn-test/src/mocha/junit_report_generation.test.js b/packages/kbn-test/src/mocha/junit_report_generation.test.js index e4e4499f556fd..2ceb95d68f598 100644 --- a/packages/kbn-test/src/mocha/junit_report_generation.test.js +++ b/packages/kbn-test/src/mocha/junit_report_generation.test.js @@ -8,8 +8,8 @@ import { resolve } from 'path'; import { readFileSync } from 'fs'; +import { promisify } from 'util'; -import { fromNode as fcb } from 'bluebird'; import { parseString } from 'xml2js'; import del from 'del'; import Mocha from 'mocha'; @@ -17,6 +17,7 @@ import { getUniqueJunitReportPath } from '../report_path'; import { setupJUnitReportGeneration } from './junit_report_generation'; +const parseStringAsync = promisify(parseString); const PROJECT_DIR = resolve(__dirname, '__fixtures__/project'); const DURATION_REGEX = /^\d+\.\d{3}$/; const ISO_DATE_SEC_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/; @@ -39,7 +40,7 @@ describe('dev/mocha/junit report generation', () => { mocha.addFile(resolve(PROJECT_DIR, 'test.js')); await new Promise((resolve) => mocha.run(resolve)); - const report = await fcb((cb) => parseString(readFileSync(XML_PATH), cb)); + const report = await parseStringAsync(readFileSync(XML_PATH)); // test case results are wrapped in expect(report).toEqual({ diff --git a/packages/kbn-utils/src/streams/map_stream.test.ts b/packages/kbn-utils/src/streams/map_stream.test.ts index 2c3df67fdf35c..39ab619b320f7 100644 --- a/packages/kbn-utils/src/streams/map_stream.test.ts +++ b/packages/kbn-utils/src/streams/map_stream.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { createPromiseFromStreams } from './promise_from_streams'; import { createListStream } from './list_stream'; @@ -39,7 +39,7 @@ describe('createMapStream()', () => { const result = await createPromiseFromStreams([ createListStream([1, 2, 3]), createMapStream(async (n: number, i: number) => { - await delay(n); + await timer(n).toPromise(); return n * i; }), createConcatStream([]), diff --git a/src/dev/notice/bundled_notices.js b/src/dev/notice/bundled_notices.js index 7ab2a5b3f03fe..15a0f6ec1e2f1 100644 --- a/src/dev/notice/bundled_notices.js +++ b/src/dev/notice/bundled_notices.js @@ -7,18 +7,18 @@ */ import { resolve } from 'path'; -import { readFile } from 'fs'; - -import { fromNode as fcb } from 'bluebird'; +import { readFile } from 'fs/promises'; +import { promisify } from 'util'; import glob from 'glob'; +const globAsync = promisify(glob); export async function getBundledNotices(packageDirectory) { const pattern = resolve(packageDirectory, '*{LICENSE,NOTICE}*'); - const paths = await fcb((cb) => glob(pattern, cb)); + const paths = await globAsync(pattern); return Promise.all( paths.map(async (path) => ({ path, - text: await fcb((cb) => readFile(path, 'utf8', cb)), + text: await readFile(path, 'utf8'), })) ); } diff --git a/src/dev/precommit_hook/get_files_for_commit.js b/src/dev/precommit_hook/get_files_for_commit.js index 44c8c9d5e6bc0..4f913ce99cdc0 100644 --- a/src/dev/precommit_hook/get_files_for_commit.js +++ b/src/dev/precommit_hook/get_files_for_commit.js @@ -7,11 +7,9 @@ */ import SimpleGit from 'simple-git'; -import { fromNode as fcb } from 'bluebird'; - import { REPO_ROOT } from '@kbn/utils'; import { File } from '../file'; - +import { promisify } from 'util'; /** * Get the files that are staged for commit (excluding deleted files) * as `File` objects that are aware of their commit status. @@ -21,8 +19,10 @@ import { File } from '../file'; */ export async function getFilesForCommit(gitRef) { const simpleGit = new SimpleGit(REPO_ROOT); + const diffAsync = promisify(simpleGit.diff).bind(simpleGit); + const gitRefForDiff = gitRef ? gitRef : '--cached'; - const output = await fcb((cb) => simpleGit.diff(['--name-status', gitRefForDiff], cb)); + const output = await diffAsync(['--name-status', gitRefForDiff]); return ( output diff --git a/src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js b/src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js index 2fb2be0ace7cd..5a220e5ff1420 100644 --- a/src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js +++ b/src/plugins/vis_type_tagcloud/public/components/tag_cloud.test.js @@ -6,11 +6,11 @@ * Side Public License, v 1. */ +import { once } from 'events'; import _ from 'lodash'; import d3 from 'd3'; import 'jest-canvas-mock'; -import { fromNode, delay } from 'bluebird'; import { TagCloud } from './tag_cloud'; import { setHTMLElementOffset, setSVGElementGetBBox } from '@kbn/test/jest'; @@ -127,7 +127,7 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(currentTest.data); tagCloud.setOptions(currentTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -161,7 +161,7 @@ describe('tag cloud tests', () => { //this timeout modifies the settings before the cloud is rendered. //the cloud needs to use the correct options setTimeout(() => tagCloud.setOptions(logScaleTest.options), timeout); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -189,7 +189,7 @@ describe('tag cloud tests', () => { tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); tagCloud.setOptions(logScaleTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -216,7 +216,7 @@ describe('tag cloud tests', () => { tagCloud.setOptions(baseTest.options); tagCloud.setData(trimDataTest.data); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -290,8 +290,7 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(logScaleTest.data); tagCloud.setOptions(logScaleTest.options); - - await delay(1000); //let layout run + await once(tagCloud, 'renderComplete'); //let layout run SVGElementGetBBoxSpyInstance.mockRestore(); SVGElementGetBBoxSpyInstance = setSVGElementGetBBox(600, 600); @@ -302,7 +301,7 @@ describe('tag cloud tests', () => { tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); }, 200); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -327,7 +326,7 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -349,12 +348,12 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); //make bigger tagCloud._size = [600, 600]; tagCloud.resize(); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -372,12 +371,12 @@ describe('tag cloud tests', () => { tagCloud = new TagCloud(domNode, colorScale); tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); //make smaller tagCloud._size = []; tagCloud.resize(); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); }); afterEach(teardownDOM); @@ -395,7 +394,7 @@ describe('tag cloud tests', () => { tagCloud.setData(baseTest.data); tagCloud.setOptions(baseTest.options); - await fromNode((cb) => tagCloud.once('renderComplete', cb)); + await once(tagCloud, 'renderComplete'); expect(domNode.innerHTML).toMatchSnapshot(); }); diff --git a/src/plugins/vis_type_timelion/server/series_functions/quandl.js b/src/plugins/vis_type_timelion/server/series_functions/quandl.js index 7e3a0f6de9aba..0176919671933 100644 --- a/src/plugins/vis_type_timelion/server/series_functions/quandl.js +++ b/src/plugins/vis_type_timelion/server/series_functions/quandl.js @@ -10,8 +10,6 @@ import { i18n } from '@kbn/i18n'; import _ from 'lodash'; import fetch from 'node-fetch'; import moment from 'moment'; -fetch.Promise = require('bluebird'); - import Datasource from '../lib/classes/datasource'; export default new Datasource('quandl', { diff --git a/test/functional/page_objects/common_page.ts b/test/functional/page_objects/common_page.ts index c6412f55dffbf..92cbd7e6d6fbe 100644 --- a/test/functional/page_objects/common_page.ts +++ b/test/functional/page_objects/common_page.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import expect from '@kbn/expect'; // @ts-ignore import fetch from 'node-fetch'; @@ -198,7 +198,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo async sleep(sleepMilliseconds: number) { log.debug(`... sleep(${sleepMilliseconds}) start`); - await delay(sleepMilliseconds); + await timer(sleepMilliseconds).toPromise(); log.debug(`... sleep(${sleepMilliseconds}) end`); } diff --git a/test/functional/page_objects/login_page.ts b/test/functional/page_objects/login_page.ts index 606ddf4643c40..6b842b5cf4ad3 100644 --- a/test/functional/page_objects/login_page.ts +++ b/test/functional/page_objects/login_page.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { FtrProviderContext } from '../ftr_provider_context'; export function LoginPageProvider({ getService }: FtrProviderContext) { @@ -62,7 +62,7 @@ export function LoginPageProvider({ getService }: FtrProviderContext) { async sleep(sleepMilliseconds: number) { log.debug(`... sleep(${sleepMilliseconds}) start`); - await delay(sleepMilliseconds); + await timer(sleepMilliseconds).toPromise(); log.debug(`... sleep(${sleepMilliseconds}) end`); } } diff --git a/test/functional/page_objects/management/saved_objects_page.ts b/test/functional/page_objects/management/saved_objects_page.ts index c28d351aa77fb..0b38ecb8a61fa 100644 --- a/test/functional/page_objects/management/saved_objects_page.ts +++ b/test/functional/page_objects/management/saved_objects_page.ts @@ -7,7 +7,6 @@ */ import { keyBy } from 'lodash'; -import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../../ftr_provider_context'; export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProviderContext) { @@ -182,53 +181,55 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv async getElementsInTable() { const rows = await testSubjects.findAll('~savedObjectsTableRow'); - return mapAsync(rows, async (row) => { - const checkbox = await row.findByCssSelector('[data-test-subj*="checkboxSelectRow"]'); - // return the object type aria-label="index patterns" - const objectType = await row.findByTestSubject('objectType'); - const titleElement = await row.findByTestSubject('savedObjectsTableRowTitle'); - // not all rows have inspect button - Advanced Settings objects don't - // Advanced Settings has 2 actions, - // data-test-subj="savedObjectsTableAction-relationships" - // data-test-subj="savedObjectsTableAction-copy_saved_objects_to_space" - // Some other objects have the ... - // data-test-subj="euiCollapsedItemActionsButton" - // Maybe some objects still have the inspect element visible? - // !!! Also note that since we don't have spaces on OSS, the actions for the same object can be different depending on OSS or not - let menuElement = null; - let inspectElement = null; - let relationshipsElement = null; - let copySaveObjectsElement = null; - const actions = await row.findByClassName('euiTableRowCell--hasActions'); - // getting the innerHTML and checking if it 'includes' a string is faster than a timeout looking for each element - const actionsHTML = await actions.getAttribute('innerHTML'); - if (actionsHTML.includes('euiCollapsedItemActionsButton')) { - menuElement = await row.findByTestSubject('euiCollapsedItemActionsButton'); - } - if (actionsHTML.includes('savedObjectsTableAction-inspect')) { - inspectElement = await row.findByTestSubject('savedObjectsTableAction-inspect'); - } - if (actionsHTML.includes('savedObjectsTableAction-relationships')) { - relationshipsElement = await row.findByTestSubject( - 'savedObjectsTableAction-relationships' - ); - } - if (actionsHTML.includes('savedObjectsTableAction-copy_saved_objects_to_space')) { - copySaveObjectsElement = await row.findByTestSubject( - 'savedObjectsTableAction-copy_saved_objects_to_space' - ); - } - return { - checkbox, - objectType: await objectType.getAttribute('aria-label'), - titleElement, - title: await titleElement.getVisibleText(), - menuElement, - inspectElement, - relationshipsElement, - copySaveObjectsElement, - }; - }); + return await Promise.all( + rows.map(async (row) => { + const checkbox = await row.findByCssSelector('[data-test-subj*="checkboxSelectRow"]'); + // return the object type aria-label="index patterns" + const objectType = await row.findByTestSubject('objectType'); + const titleElement = await row.findByTestSubject('savedObjectsTableRowTitle'); + // not all rows have inspect button - Advanced Settings objects don't + // Advanced Settings has 2 actions, + // data-test-subj="savedObjectsTableAction-relationships" + // data-test-subj="savedObjectsTableAction-copy_saved_objects_to_space" + // Some other objects have the ... + // data-test-subj="euiCollapsedItemActionsButton" + // Maybe some objects still have the inspect element visible? + // !!! Also note that since we don't have spaces on OSS, the actions for the same object can be different depending on OSS or not + let menuElement = null; + let inspectElement = null; + let relationshipsElement = null; + let copySaveObjectsElement = null; + const actions = await row.findByClassName('euiTableRowCell--hasActions'); + // getting the innerHTML and checking if it 'includes' a string is faster than a timeout looking for each element + const actionsHTML = await actions.getAttribute('innerHTML'); + const [ + menuElement = null, + inspectElement = null, + relationshipsElement = null, + copySaveObjectsElement = null, + ] = Promise.all([ + actionsHTML.includes('euiCollapsedItemActionsButton') && + row.findByTestSubject('euiCollapsedItemActionsButton'), + actionsHTML.includes('savedObjectsTableAction-inspect') && + row.findByTestSubject('savedObjectsTableAction-inspect'), + actionsHTML.includes('savedObjectsTableAction-relationships') && + row.findByTestSubject('savedObjectsTableAction-relationships'), + actionsHTML.includes('savedObjectsTableAction-copy_saved_objects_to_space') && + row.findByTestSubject('savedObjectsTableAction-copy_saved_objects_to_space'), + ]); + + return { + checkbox, + objectType: await objectType.getAttribute('aria-label'), + titleElement, + title: await titleElement.getVisibleText(), + menuElement, + inspectElement, + relationshipsElement, + copySaveObjectsElement, + }; + }) + ); } async getRowTitles() { @@ -242,35 +243,39 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv async getRelationshipFlyout() { const rows = await testSubjects.findAll('relationshipsTableRow'); - return mapAsync(rows, async (row) => { - const objectType = await row.findByTestSubject('relationshipsObjectType'); - const relationship = await row.findByTestSubject('directRelationship'); - const titleElement = await row.findByTestSubject('relationshipsTitle'); - const inspectElement = await row.findByTestSubject('relationshipsTableAction-inspect'); - return { - objectType: await objectType.getAttribute('aria-label'), - relationship: await relationship.getVisibleText(), - titleElement, - title: await titleElement.getVisibleText(), - inspectElement, - }; - }); + return Promise.all( + rows.map(async (row) => { + const objectType = await row.findByTestSubject('relationshipsObjectType'); + const relationship = await row.findByTestSubject('directRelationship'); + const titleElement = await row.findByTestSubject('relationshipsTitle'); + const inspectElement = await row.findByTestSubject('relationshipsTableAction-inspect'); + return { + objectType: await objectType.getAttribute('aria-label'), + relationship: await relationship.getVisibleText(), + titleElement, + title: await titleElement.getVisibleText(), + inspectElement, + }; + }) + ); } async getInvalidRelations() { const rows = await testSubjects.findAll('invalidRelationshipsTableRow'); - return mapAsync(rows, async (row) => { - const objectType = await row.findByTestSubject('relationshipsObjectType'); - const objectId = await row.findByTestSubject('relationshipsObjectId'); - const relationship = await row.findByTestSubject('directRelationship'); - const error = await row.findByTestSubject('relationshipsError'); - return { - type: await objectType.getVisibleText(), - id: await objectId.getVisibleText(), - relationship: await relationship.getVisibleText(), - error: await error.getVisibleText(), - }; - }); + return Promise.all( + rows.map(async (row) => { + const objectType = await row.findByTestSubject('relationshipsObjectType'); + const objectId = await row.findByTestSubject('relationshipsObjectId'); + const relationship = await row.findByTestSubject('directRelationship'); + const error = await row.findByTestSubject('relationshipsError'); + return { + type: await objectType.getVisibleText(), + id: await objectId.getVisibleText(), + relationship: await relationship.getVisibleText(), + error: await error.getVisibleText(), + }; + }) + ); } async getTableSummary() { diff --git a/test/functional/page_objects/settings_page.ts b/test/functional/page_objects/settings_page.ts index 4151a8c1a1893..0278fc8c40837 100644 --- a/test/functional/page_objects/settings_page.ts +++ b/test/functional/page_objects/settings_page.ts @@ -6,9 +6,8 @@ * Side Public License, v 1. */ -import { map as mapAsync } from 'bluebird'; import expect from '@kbn/expect'; -import { FtrProviderContext } from '../ftr_provider_context'; +import { FtrProviderContext } from '../)ftr_provider_context'; export function SettingsPageProvider({ getService, getPageObjects }: FtrProviderContext) { const log = getService('log'); @@ -200,23 +199,29 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider async getFieldNames() { const fieldNameCells = await testSubjects.findAll('editIndexPattern > indexedFieldName'); - return await mapAsync(fieldNameCells, async (cell) => { - return (await cell.getVisibleText()).trim(); - }); + return await Promise.all( + fieldNameCells.map(async (cell) => { + return (await cell.getVisibleText()).trim(); + }) + ); } async getFieldTypes() { const fieldNameCells = await testSubjects.findAll('editIndexPattern > indexedFieldType'); - return await mapAsync(fieldNameCells, async (cell) => { - return (await cell.getVisibleText()).trim(); - }); + return await await Promise.all( + fieldNameCells.map(async (cell) => { + return (await cell.getVisibleText()).trim(); + }) + ); } async getScriptedFieldLangs() { const fieldNameCells = await testSubjects.findAll('editIndexPattern > scriptedFieldLang'); - return await mapAsync(fieldNameCells, async (cell) => { - return (await cell.getVisibleText()).trim(); - }); + return await await Promise.all( + fieldNameCells.map(async (cell) => { + return (await cell.getVisibleText()).trim(); + }) + ); } async setFieldTypeFilter(type: string) { @@ -293,9 +298,11 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider async getAllIndexPatternNames() { const indexPatterns = await this.getIndexPatternList(); - return await mapAsync(indexPatterns, async (index) => { - return await index.getVisibleText(); - }); + return await await Promise.all( + indexPatterns.map(async (index) => { + return await index.getVisibleText(); + }) + ); } async isIndexPatternListEmpty() { diff --git a/test/functional/services/common/browser.ts b/test/functional/services/common/browser.ts index d9212e48f73fc..1c5694cd94574 100644 --- a/test/functional/services/common/browser.ts +++ b/test/functional/services/common/browser.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { cloneDeepWith } from 'lodash'; import { Key, Origin } from 'selenium-webdriver'; // @ts-ignore internal modules are not typed @@ -305,7 +305,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) { to ); // wait for 150ms to make sure the script has run - await delay(150); + await timer(150).toPromise(); } /** diff --git a/test/functional/services/common/test_subjects.ts b/test/functional/services/common/test_subjects.ts index 28b37d9576e8c..c2dfe5443e3be 100644 --- a/test/functional/services/common/test_subjects.ts +++ b/test/functional/services/common/test_subjects.ts @@ -7,7 +7,6 @@ */ import testSubjSelector from '@kbn/test-subj-selector'; -import { map as mapAsync } from 'bluebird'; import { ProvidedType } from '@kbn/test/types/ftr'; import { WebElementWrapper } from '../lib/web_element_wrapper'; import { FtrProviderContext } from '../../ftr_provider_context'; @@ -265,7 +264,7 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) { ): Promise { return await retry.try(async () => { const elements = await this.findAll(selectorAll); - return await mapAsync(elements, mapFn); + return await Promise.all(elements.map(mapFn)); }); } diff --git a/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts b/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts index 1a45aee877e1f..851938decab49 100644 --- a/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts +++ b/test/functional/services/lib/web_element_wrapper/web_element_wrapper.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { WebElement, WebDriver, By, Key } from 'selenium-webdriver'; import { PNG } from 'pngjs'; // @ts-ignore not supported yet @@ -122,7 +122,7 @@ export class WebElementWrapper { `finding element '${this.locator.toString()}' again, ${attemptsRemaining - 1} attempts left` ); - await delay(200); + await timer(200).toPromise(); this._webElement = await this.driver.findElement(this.locator); return await this.retryCall(fn, attemptsRemaining - 1); } @@ -241,7 +241,7 @@ export class WebElementWrapper { const value = await this.getAttribute('value'); for (let i = 0; i <= value.length; i++) { await this.pressKeys(this.Keys.BACK_SPACE); - await delay(100); + await timer(100).toPromise(); } } else { if (this.isChromium) { @@ -280,7 +280,7 @@ export class WebElementWrapper { for (const char of value) { await this.retryCall(async function type(wrapper) { await wrapper._webElement.sendKeys(char); - await delay(100); + await timer(100).toPromise(); }); } } else { diff --git a/utilities/visual_regression.js b/utilities/visual_regression.js index fa4d48a2280d5..50a794002c52f 100644 --- a/utilities/visual_regression.js +++ b/utilities/visual_regression.js @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import bluebird, { promisify } from 'bluebird'; +import { promisify } from 'util'; import Handlebars from 'handlebars'; import fs from 'fs'; import path from 'path'; @@ -73,56 +73,58 @@ async function compareScreenshots() { const screenshots = files.filter((file) => file.indexOf('.png') !== -1); // We'll use this data to build a screenshot gallery in HTML. - return await bluebird.map(screenshots, async (screenshot) => { - // We're going to load image data and cache it in this object. - const comparison = { - name: screenshot, - change: undefined, - percentage: undefined, - imageData: { - session: undefined, - baseline: undefined, - diff: undefined, - }, - }; - - const sessionImagePath = path.resolve(SESSION_SCREENSHOTS_DIR, screenshot); - - const baselineImagePath = path.resolve(BASELINE_SCREENSHOTS_DIR, screenshot); - - const diffImagePath = path.resolve(DIFF_SCREENSHOTS_DIR, screenshot); - - const sessionImage = PNG.sync.read(await readFileAsync(sessionImagePath)); - const baselineImage = PNG.sync.read(await readFileAsync(baselineImagePath)); - const { width, height } = sessionImage; - const diff = new PNG({ width, height }); - - const numDiffPixels = pixelmatch( - sessionImage.data, - baselineImage.data, - diff.data, - width, - height, - { threshold: 0 } - ); - - await writeFileAsync(diffImagePath, PNG.sync.write(diff)); - - const change = numDiffPixels / (width * height); - const changePercentage = (change * 100).toFixed(2); - console.log(`(${changePercentage}%) ${screenshot}`); - comparison.percentage = changePercentage; - comparison.change = change; - - // Once the images have been diffed, we can load and store the image data. - comparison.imageData.session = await readFileAsync(sessionImagePath, 'base64'); - - comparison.imageData.baseline = await readFileAsync(baselineImagePath, 'base64'); - - comparison.imageData.diff = await readFileAsync(diffImagePath, 'base64'); - - return comparison; - }); + return await Promise.all( + screenshots.map(async (screenshot) => { + // We're going to load image data and cache it in this object. + const comparison = { + name: screenshot, + change: undefined, + percentage: undefined, + imageData: { + session: undefined, + baseline: undefined, + diff: undefined, + }, + }; + + const sessionImagePath = path.resolve(SESSION_SCREENSHOTS_DIR, screenshot); + + const baselineImagePath = path.resolve(BASELINE_SCREENSHOTS_DIR, screenshot); + + const diffImagePath = path.resolve(DIFF_SCREENSHOTS_DIR, screenshot); + + const sessionImage = PNG.sync.read(await readFileAsync(sessionImagePath)); + const baselineImage = PNG.sync.read(await readFileAsync(baselineImagePath)); + const { width, height } = sessionImage; + const diff = new PNG({ width, height }); + + const numDiffPixels = pixelmatch( + sessionImage.data, + baselineImage.data, + diff.data, + width, + height, + { threshold: 0 } + ); + + await writeFileAsync(diffImagePath, PNG.sync.write(diff)); + + const change = numDiffPixels / (width * height); + const changePercentage = (change * 100).toFixed(2); + console.log(`(${changePercentage}%) ${screenshot}`); + comparison.percentage = changePercentage; + comparison.change = change; + + // Once the images have been diffed, we can load and store the image data. + comparison.imageData.session = await readFileAsync(sessionImagePath, 'base64'); + + comparison.imageData.baseline = await readFileAsync(baselineImagePath, 'base64'); + + comparison.imageData.diff = await readFileAsync(diffImagePath, 'base64'); + + return comparison; + }) + ); } export function run(done) { diff --git a/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts b/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts index 0d37979ef9acb..b1178007148d7 100644 --- a/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts +++ b/x-pack/plugins/fleet/server/routes/agent_policy/handlers.ts @@ -7,7 +7,6 @@ import type { TypeOf } from '@kbn/config-schema'; import type { RequestHandler, ResponseHeaders } from 'src/core/server'; -import bluebird from 'bluebird'; import { fullAgentPolicyToYaml } from '../../../common/services'; import { appContextService, agentPolicyService, packagePolicyService } from '../../services'; @@ -55,16 +54,17 @@ export const getAgentPoliciesHandler: RequestHandler< perPage, }; - await bluebird.map( - items, - (agentPolicy: GetAgentPoliciesResponseItem) => - getAgentsByKuery(esClient, { - showInactive: false, - perPage: 0, - page: 1, - kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id:${agentPolicy.id}`, - }).then(({ total: agentTotal }) => (agentPolicy.agents = agentTotal)), - { concurrency: 10 } + await Promise.all( + items.map( + async (agentPolicy: GetAgentPoliciesResponseItem) => + getAgentsByKuery(esClient, { + showInactive: false, + perPage: 0, + page: 1, + kuery: `${AGENT_SAVED_OBJECT_TYPE}.policy_id:${agentPolicy.id}`, + }).then(({ total: agentTotal }) => (agentPolicy.agents = agentTotal)), + { concurrency: 10 } + ) ); return response.ok({ body }); diff --git a/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts b/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts index 582969f1dcd45..a0c3bf792797d 100644 --- a/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts +++ b/x-pack/plugins/security_solution/scripts/endpoint/trusted_apps/index.ts @@ -9,7 +9,7 @@ import minimist from 'minimist'; import { ToolingLog } from '@kbn/dev-utils'; import { KbnClient } from '@kbn/test'; -import bluebird from 'bluebird'; +import { chain } from 'lodash'; import { basename } from 'path'; import { TRUSTED_APPS_CREATE_API, TRUSTED_APPS_LIST_API } from '../../../common/endpoint/constants'; import { NewTrustedApp, OperatingSystem, TrustedApp } from '../../../common/endpoint/types'; @@ -73,21 +73,28 @@ export const run: (options?: RunOptions) => Promise = async ({ path: TRUSTED_APPS_LIST_API, }); - return bluebird.map( - Array.from({ length: count }), - () => - kbnClient - .request({ - method: 'POST', - path: TRUSTED_APPS_CREATE_API, - body: generateTrustedAppEntry(), - }) - .then(({ data }) => { - logger.write(data.id); - return data; - }), - { concurrency: 10 } - ); + const results = []; + + // 10 concurrent requests at a time. + const invokeRequestChunks = chain(Array(count)) + .fill(async () => { + const { data } = await kbnClient.request({ + method: 'POST', + path: TRUSTED_APPS_CREATE_API, + body: generateTrustedAppEntry(), + }); + logger.write(data.id); + return data; + }) + .chunk(10) + .value(); + + for await (const invokeRequestChunk of invokeRequestChunks) { + const result = await Promise.all(invokeRequestChunk.map(invokeRequest)); + results.concat(result); + } + + return results; }; interface GenerateTrustedAppEntryOptions { diff --git a/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts b/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts index f47e79260e61c..034ce1dd75fa6 100644 --- a/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts +++ b/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts @@ -4,7 +4,6 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../ftr_provider_context'; export function IndexLifecycleManagementPageProvider({ getService }: FtrProviderContext) { @@ -57,27 +56,29 @@ export function IndexLifecycleManagementPageProvider({ getService }: FtrProvider async getPolicyList() { const policies = await testSubjects.findAll('policyTableRow'); - return mapAsync(policies, async (policy) => { - const policyNameElement = await policy.findByTestSubject('policyTableCell-name'); - const policyLinkedIndicesElement = await policy.findByTestSubject( - 'policyTableCell-linkedIndices' - ); - const policyVersionElement = await policy.findByTestSubject('policyTableCell-version'); - const policyModifiedDateElement = await policy.findByTestSubject( - 'policyTableCell-modified_date' - ); - const policyActionsButtonElement = await policy.findByTestSubject( - 'policyActionsContextMenuButton' - ); + return await Promise.all( + policies.map(async (policy) => { + const policyNameElement = await policy.findByTestSubject('policyTableCell-name'); + const policyLinkedIndicesElement = await policy.findByTestSubject( + 'policyTableCell-linkedIndices' + ); + const policyVersionElement = await policy.findByTestSubject('policyTableCell-version'); + const policyModifiedDateElement = await policy.findByTestSubject( + 'policyTableCell-modified_date' + ); + const policyActionsButtonElement = await policy.findByTestSubject( + 'policyActionsContextMenuButton' + ); - return { - name: await policyNameElement.getVisibleText(), - linkedIndices: await policyLinkedIndicesElement.getVisibleText(), - version: await policyVersionElement.getVisibleText(), - modifiedDate: await policyModifiedDateElement.getVisibleText(), - actionsButton: policyActionsButtonElement, - }; - }); + return { + name: await policyNameElement.getVisibleText(), + linkedIndices: await policyLinkedIndicesElement.getVisibleText(), + version: await policyVersionElement.getVisibleText(), + modifiedDate: await policyModifiedDateElement.getVisibleText(), + actionsButton: policyActionsButtonElement, + }; + }) + ); }, }; } diff --git a/x-pack/test/functional/page_objects/rollup_page.ts b/x-pack/test/functional/page_objects/rollup_page.ts index dbdfa4e19c555..47f964d8847cd 100644 --- a/x-pack/test/functional/page_objects/rollup_page.ts +++ b/x-pack/test/functional/page_objects/rollup_page.ts @@ -6,7 +6,6 @@ */ import expect from '@kbn/expect'; -import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../ftr_provider_context'; export function RollupPageProvider({ getService, getPageObjects }: FtrProviderContext) { @@ -112,31 +111,33 @@ export function RollupPageProvider({ getService, getPageObjects }: FtrProviderCo async getJobList() { const jobs = await testSubjects.findAll('jobTableRow'); - return mapAsync(jobs, async (job) => { - const jobNameElement = await job.findByTestSubject('jobTableCell-id'); - const jobStatusElement = await job.findByTestSubject('jobTableCell-status'); - const jobIndexPatternElement = await job.findByTestSubject('jobTableCell-indexPattern'); - const jobRollUpIndexPatternElement = await job.findByTestSubject( - 'jobTableCell-rollupIndex' - ); - const jobDelayElement = await job.findByTestSubject('jobTableCell-rollupDelay'); - const jobIntervalElement = await job.findByTestSubject( - 'jobTableCell-dateHistogramInterval' - ); - const jobGroupElement = await job.findByTestSubject('jobTableCell-groups'); - const jobMetricsElement = await job.findByTestSubject('jobTableCell-metrics'); - - return { - jobName: await jobNameElement.getVisibleText(), - jobStatus: await jobStatusElement.getVisibleText(), - jobIndexPattern: await jobIndexPatternElement.getVisibleText(), - jobRollUpIndexPattern: await jobRollUpIndexPatternElement.getVisibleText(), - jobDelayElement: await jobDelayElement.getVisibleText(), - jobInterval: await jobIntervalElement.getVisibleText(), - jobGroup: await jobGroupElement.getVisibleText(), - jobMetrics: await jobMetricsElement.getVisibleText(), - }; - }); + return Promise.all( + jobs.map(async (job) => { + const jobNameElement = await job.findByTestSubject('jobTableCell-id'); + const jobStatusElement = await job.findByTestSubject('jobTableCell-status'); + const jobIndexPatternElement = await job.findByTestSubject('jobTableCell-indexPattern'); + const jobRollUpIndexPatternElement = await job.findByTestSubject( + 'jobTableCell-rollupIndex' + ); + const jobDelayElement = await job.findByTestSubject('jobTableCell-rollupDelay'); + const jobIntervalElement = await job.findByTestSubject( + 'jobTableCell-dateHistogramInterval' + ); + const jobGroupElement = await job.findByTestSubject('jobTableCell-groups'); + const jobMetricsElement = await job.findByTestSubject('jobTableCell-metrics'); + + return { + jobName: await jobNameElement.getVisibleText(), + jobStatus: await jobStatusElement.getVisibleText(), + jobIndexPattern: await jobIndexPatternElement.getVisibleText(), + jobRollUpIndexPattern: await jobRollUpIndexPatternElement.getVisibleText(), + jobDelayElement: await jobDelayElement.getVisibleText(), + jobInterval: await jobIntervalElement.getVisibleText(), + jobGroup: await jobGroupElement.getVisibleText(), + jobMetrics: await jobMetricsElement.getVisibleText(), + }; + }) + ); } } return new RollupJobPage(); diff --git a/x-pack/test/functional/page_objects/watcher_page.ts b/x-pack/test/functional/page_objects/watcher_page.ts index d0db5c8c3b267..2627ff0fa8105 100644 --- a/x-pack/test/functional/page_objects/watcher_page.ts +++ b/x-pack/test/functional/page_objects/watcher_page.ts @@ -5,7 +5,6 @@ * 2.0. */ -import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../ftr_provider_context'; export function WatcherPageProvider({ getPageObjects, getService }: FtrProviderContext) { @@ -52,17 +51,19 @@ export function WatcherPageProvider({ getPageObjects, getService }: FtrProviderC // get all the watches in the list async getWatches() { const watches = await find.allByCssSelector('.euiTableRow'); - return mapAsync(watches, async (watch) => { - const checkBox = await watch.findByCssSelector('td:nth-child(1)'); - const id = await watch.findByCssSelector('td:nth-child(2)'); - const name = await watch.findByCssSelector('td:nth-child(3)'); + return Promise.all( + watches.map(async (watch) => { + const checkBox = await watch.findByCssSelector('td:nth-child(1)'); + const id = await watch.findByCssSelector('td:nth-child(2)'); + const name = await watch.findByCssSelector('td:nth-child(3)'); - return { - checkBox: (await checkBox.getAttribute('innerHTML')).includes('input'), - id: await id.getVisibleText(), - name: (await name.getVisibleText()).split(',').map((role) => role.trim()), - }; - }); + return { + checkBox: (await checkBox.getAttribute('innerHTML')).includes('input'), + id: await id.getVisibleText(), + name: (await name.getVisibleText()).split(',').map((role) => role.trim()), + }; + }) + ); } } return new WatcherPage(); diff --git a/x-pack/test/functional/services/ace_editor.js b/x-pack/test/functional/services/ace_editor.js index 589f05695e065..be74708749f84 100644 --- a/x-pack/test/functional/services/ace_editor.js +++ b/x-pack/test/functional/services/ace_editor.js @@ -5,8 +5,6 @@ * 2.0. */ -import { map as mapAsync } from 'bluebird'; - export function AceEditorProvider({ getService }) { const testSubjects = getService('testSubjects'); const find = getService('find'); @@ -35,7 +33,8 @@ export function AceEditorProvider({ getService }) { return await retry.try(async () => { const editor = await testSubjects.find(testSubjectSelector); const lines = await editor.findAllByClassName('ace_line'); - const linesText = await mapAsync(lines, (line) => line.getVisibleText()); + + const linesText = await Promise.all(lines.map((line) => line.getVisibleText())); return linesText.join('\n'); }); } diff --git a/x-pack/test/functional/services/monitoring/cluster_alerts.js b/x-pack/test/functional/services/monitoring/cluster_alerts.js index cbeb537b08016..34c0907c3c0e2 100644 --- a/x-pack/test/functional/services/monitoring/cluster_alerts.js +++ b/x-pack/test/functional/services/monitoring/cluster_alerts.js @@ -6,7 +6,6 @@ */ import { range } from 'lodash'; -import { map as mapAsync } from 'bluebird'; export function MonitoringClusterAlertsProvider({ getService, getPageObjects }) { const testSubjects = getService('testSubjects'); @@ -61,9 +60,7 @@ export function MonitoringClusterAlertsProvider({ getService, getPageObjects }) const listingRows = await this.getOverviewAlerts(); const alertIcons = await retry.try(async () => { const elements = await find.allByCssSelector(SUBJ_OVERVIEW_ICONS); - return await mapAsync(elements, async (element) => { - return await element.getVisibleText(); - }); + return await Promise.all(elements.map(async (element) => await element.getVisibleText())); }); return await this._getAlertSetAll({ diff --git a/x-pack/test/functional/services/pipeline_editor.js b/x-pack/test/functional/services/pipeline_editor.js index ece7ec5b3ecbc..77d6d05778335 100644 --- a/x-pack/test/functional/services/pipeline_editor.js +++ b/x-pack/test/functional/services/pipeline_editor.js @@ -6,7 +6,6 @@ */ import expect from '@kbn/expect'; -import { props as propsAsync } from 'bluebird'; export function PipelineEditorProvider({ getService }) { const retry = getService('retry'); @@ -125,22 +124,39 @@ export function PipelineEditorProvider({ getService }) { * @return {Promise} */ async assertInputs(expectedValues) { - const values = await propsAsync({ - id: testSubjects.getAttribute(SUBJ_INPUT_ID, 'value'), - description: testSubjects.getAttribute(SUBJ_INPUT_DESCRIPTION, 'value'), - pipeline: aceEditor.getValue(SUBJ_UI_ACE_PIPELINE), - workers: testSubjects.getAttribute(SUBJ_INPUT_WORKERS, 'value'), - batchSize: testSubjects.getAttribute(SUBJ_INPUT_BATCH_SIZE, 'value'), - queueType: testSubjects.getAttribute(SUBJ_SELECT_QUEUE_TYPE, 'value'), - queueMaxBytesNumber: testSubjects.getAttribute(SUBJ_INPUT_QUEUE_MAX_BYTES_NUMBER, 'value'), - queueMaxBytesUnits: testSubjects.getAttribute(SUBJ_SELECT_QUEUE_MAX_BYTES_UNITS, 'value'), - queueCheckpointWrites: testSubjects.getAttribute( - SUBJ_INPUT_QUEUE_CHECKPOINT_WRITES, - 'value' - ), - }); + const [ + id, + description, + pipeline, + workers, + batchSize, + queueType, + queueMaxBytesNumber, + queueMaxBytesUnits, + queueCheckpointWrites, + ] = Promise.all([ + testSubjects.getAttribute(SUBJ_INPUT_ID, 'value'), + testSubjects.getAttribute(SUBJ_INPUT_DESCRIPTION, 'value'), + aceEditor.getValue(SUBJ_UI_ACE_PIPELINE), + testSubjects.getAttribute(SUBJ_INPUT_WORKERS, 'value'), + testSubjects.getAttribute(SUBJ_INPUT_BATCH_SIZE, 'value'), + testSubjects.getAttribute(SUBJ_SELECT_QUEUE_TYPE, 'value'), + testSubjects.getAttribute(SUBJ_INPUT_QUEUE_MAX_BYTES_NUMBER, 'value'), + testSubjects.getAttribute(SUBJ_SELECT_QUEUE_MAX_BYTES_UNITS, 'value'), + testSubjects.getAttribute(SUBJ_INPUT_QUEUE_CHECKPOINT_WRITES, 'value'), + ]); - expect(values).to.eql(expectedValues); + expect({ + id, + description, + pipeline, + workers, + batchSize, + queueType, + queueMaxBytesNumber, + queueMaxBytesUnits, + queueCheckpointWrites, + }).to.eql(expectedValues); } async assertNoDeleteButton() { diff --git a/x-pack/test/security_api_integration/tests/kerberos/kerberos_login.ts b/x-pack/test/security_api_integration/tests/kerberos/kerberos_login.ts index 2fe88dc21e5e0..82f065ef00fe5 100644 --- a/x-pack/test/security_api_integration/tests/kerberos/kerberos_login.ts +++ b/x-pack/test/security_api_integration/tests/kerberos/kerberos_login.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import request, { Cookie } from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { adminTestUser } from '@kbn/test'; import { FtrProviderContext } from '../../ftr_provider_context'; import { @@ -309,7 +309,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This api call should succeed and automatically refresh token. Returned cookie will contain // the new access and refresh token pair. @@ -340,7 +340,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This request should succeed and automatically refresh token. Returned cookie will contain // the new access and refresh token pair. diff --git a/x-pack/test/security_api_integration/tests/oidc/authorization_code_flow/oidc_auth.ts b/x-pack/test/security_api_integration/tests/oidc/authorization_code_flow/oidc_auth.ts index b2dd65b4f2009..94c807b7b06df 100644 --- a/x-pack/test/security_api_integration/tests/oidc/authorization_code_flow/oidc_auth.ts +++ b/x-pack/test/security_api_integration/tests/oidc/authorization_code_flow/oidc_auth.ts @@ -8,7 +8,7 @@ import expect from '@kbn/expect'; import request, { Cookie } from 'request'; import url from 'url'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { adminTestUser } from '@kbn/test'; import { getStateAndNonce } from '../../../fixtures/oidc/oidc_tools'; import { FtrProviderContext } from '../../../ftr_provider_context'; @@ -515,7 +515,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This api call should succeed and automatically refresh token. Returned cookie will contain // the new access and refresh token pair. diff --git a/x-pack/test/security_api_integration/tests/pki/pki_auth.ts b/x-pack/test/security_api_integration/tests/pki/pki_auth.ts index e3f63aad9e255..97c1f55646f0d 100644 --- a/x-pack/test/security_api_integration/tests/pki/pki_auth.ts +++ b/x-pack/test/security_api_integration/tests/pki/pki_auth.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import request, { Cookie } from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import { readFileSync } from 'fs'; import { resolve } from 'path'; import { CA_CERT_PATH } from '@kbn/dev-utils'; @@ -344,7 +344,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This api call should succeed and automatically refresh token. Returned cookie will contain // the new access token. @@ -368,7 +368,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); // This request should succeed and automatically refresh token. Returned cookie will contain // the new access and refresh token pair. diff --git a/x-pack/test/security_api_integration/tests/saml/saml_login.ts b/x-pack/test/security_api_integration/tests/saml/saml_login.ts index e199ba99bfc58..d8a9f42d777ef 100644 --- a/x-pack/test/security_api_integration/tests/saml/saml_login.ts +++ b/x-pack/test/security_api_integration/tests/saml/saml_login.ts @@ -7,7 +7,7 @@ import { stringify } from 'query-string'; import url from 'url'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import expect from '@kbn/expect'; import request, { Cookie } from 'request'; import { adminTestUser } from '@kbn/test'; @@ -482,7 +482,7 @@ export default function ({ getService }: FtrProviderContext) { // Access token expiration is set to 15s for API integration tests. // Let's wait for 20s to make sure token expires. - await delay(20000); + await timer(20000).toPromise(); }); const expectNewSessionCookie = (cookie: Cookie) => { @@ -661,7 +661,7 @@ export default function ({ getService }: FtrProviderContext) { ['when access token is valid', async () => {}], // Scenario when active cookie has an expired access token. Access token expiration is set // to 15s for API integration tests so we need to wait for 20s to make sure token expires. - ['when access token is expired', async () => await delay(20000)], + ['when access token is expired', async () => await timer(20000).toPromise()], // Scenario when active cookie references to access/refresh token pair that were already // removed from Elasticsearch (to simulate 24h when expired tokens are removed). [ diff --git a/x-pack/test/security_api_integration/tests/session_idle/cleanup.ts b/x-pack/test/security_api_integration/tests/session_idle/cleanup.ts index 84f84e8752122..249eabe094e4f 100644 --- a/x-pack/test/security_api_integration/tests/session_idle/cleanup.ts +++ b/x-pack/test/security_api_integration/tests/session_idle/cleanup.ts @@ -6,7 +6,7 @@ */ import request, { Cookie } from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import expect from '@kbn/expect'; import { adminTestUser } from '@kbn/test'; import type { AuthenticationProvider } from '../../../../plugins/security/common/model'; @@ -99,7 +99,7 @@ export default function ({ getService }: FtrProviderContext) { // Cleanup routine runs every 10s, and idle timeout threshold is three times larger than 5s // idle timeout, let's wait for 40s to make sure cleanup routine runs when idle timeout // threshold is exceeded. - await delay(40000); + await timer(40000).toPromise(); // Session info is removed from the index and cookie isn't valid anymore expect(await getNumberOfSessionDocuments()).to.be(0); @@ -144,7 +144,7 @@ export default function ({ getService }: FtrProviderContext) { // Cleanup routine runs every 10s, and idle timeout threshold is three times larger than 5s // idle timeout, let's wait for 40s to make sure cleanup routine runs when idle timeout // threshold is exceeded. - await delay(40000); + await timer(40000).toPromise(); // Session for basic and SAML that used global session settings should not be valid anymore. expect(await getNumberOfSessionDocuments()).to.be(2); @@ -192,7 +192,7 @@ export default function ({ getService }: FtrProviderContext) { // least twice. for (const counter of [...Array(20).keys()]) { // Session idle timeout is 15s, let's wait 10s and make a new request that would extend the session. - await delay(1500); + await timer(1500).toPromise(); sessionCookie = (await checkSessionCookie(sessionCookie, basicUsername, { type: 'basic', diff --git a/x-pack/test/security_api_integration/tests/session_lifespan/cleanup.ts b/x-pack/test/security_api_integration/tests/session_lifespan/cleanup.ts index 3d24efc9b8e74..80c48aed571b2 100644 --- a/x-pack/test/security_api_integration/tests/session_lifespan/cleanup.ts +++ b/x-pack/test/security_api_integration/tests/session_lifespan/cleanup.ts @@ -6,7 +6,7 @@ */ import request, { Cookie } from 'request'; -import { delay } from 'bluebird'; +import { timer } from 'rxjs'; import expect from '@kbn/expect'; import { adminTestUser } from '@kbn/test'; import type { AuthenticationProvider } from '../../../../plugins/security/common/model'; @@ -96,7 +96,7 @@ export default function ({ getService }: FtrProviderContext) { // Cleanup routine runs every 10s, let's wait for 40s to make sure it runs multiple times and // when lifespan is exceeded. - await delay(40000); + await timer(40000).toPromise(); // Session info is removed from the index and cookie isn't valid anymore expect(await getNumberOfSessionDocuments()).to.be(0); @@ -139,7 +139,7 @@ export default function ({ getService }: FtrProviderContext) { // Cleanup routine runs every 10s, let's wait for 40s to make sure it runs multiple times and // when lifespan is exceeded. - await delay(40000); + await timer(40000).toPromise(); // Session for basic and SAML that used global session settings should not be valid anymore. expect(await getNumberOfSessionDocuments()).to.be(2);