From 4ea7dc00293e7b67160aaf6092da26648a2ac8f7 Mon Sep 17 00:00:00 2001 From: Chi Cao Minh Date: Fri, 2 Oct 2020 15:17:58 -0700 Subject: [PATCH] Test UI to trigger auto compaction In the web console E2E tests, Use the new UI to trigger auto compaction instead of calling the REST API directly so that the UI is covered by tests. --- web-console/e2e-tests/auto-compaction.spec.ts | 21 +++++------ .../component/datasources/overview.ts | 35 ++++++++++++++++--- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/web-console/e2e-tests/auto-compaction.spec.ts b/web-console/e2e-tests/auto-compaction.spec.ts index 68cd00b0287a..496e56a2e56f 100644 --- a/web-console/e2e-tests/auto-compaction.spec.ts +++ b/web-console/e2e-tests/auto-compaction.spec.ts @@ -16,7 +16,6 @@ * limitations under the License. */ -import axios from 'axios'; import path from 'path'; import * as playwright from 'playwright-core'; @@ -25,7 +24,6 @@ import { Datasource } from './component/datasources/datasource'; import { DatasourcesOverview } from './component/datasources/overview'; import { HashedPartitionsSpec } from './component/load-data/config/partition'; import { saveScreenshotIfError } from './util/debug'; -import { COORDINATOR_URL } from './util/druid'; import { DRUID_EXAMPLES_QUICKSTART_TUTORIAL_DIR } from './util/druid'; import { UNIFIED_CONSOLE_URL } from './util/druid'; import { runIndexTask } from './util/druid'; @@ -77,7 +75,7 @@ describe('Auto-compaction', () => { // need several iterations if several time chunks need compaction let currNumSegment = uncompactedNumSegment; await retryIfJestAssertionError(async () => { - await triggerCompaction(); + await triggerCompaction(page); currNumSegment = await waitForCompaction(page, datasourceName, currNumSegment); const compactedNumSegment = 2; @@ -127,15 +125,18 @@ async function configureCompaction( const datasourcesOverview = new DatasourcesOverview(page, UNIFIED_CONSOLE_URL); await datasourcesOverview.setCompactionConfiguration(datasourceName, compactionConfig); - const savedCompactionConfig = await datasourcesOverview.getCompactionConfiguration( - datasourceName, - ); - expect(savedCompactionConfig).toEqual(compactionConfig); + // Saving the compaction config is not instantaneous + await retryIfJestAssertionError(async () => { + const savedCompactionConfig = await datasourcesOverview.getCompactionConfiguration( + datasourceName, + ); + expect(savedCompactionConfig).toEqual(compactionConfig); + }); } -async function triggerCompaction() { - const res = await axios.post(`${COORDINATOR_URL}/druid/coordinator/v1/compaction/compact`); - expect(res.status).toBe(200); +async function triggerCompaction(page: playwright.Page) { + const datasourcesOverview = new DatasourcesOverview(page, UNIFIED_CONSOLE_URL); + await datasourcesOverview.triggerCompaction(); } async function waitForCompaction( diff --git a/web-console/e2e-tests/component/datasources/overview.ts b/web-console/e2e-tests/component/datasources/overview.ts index 11f44b48d410..c322b0338b46 100644 --- a/web-console/e2e-tests/component/datasources/overview.ts +++ b/web-console/e2e-tests/component/datasources/overview.ts @@ -44,7 +44,6 @@ enum DatasourceColumn { ACTIONS, } -const EDIT_COMPACTION_CONFIGURATION = 'Edit compaction configuration'; const SKIP_OFFSET_FROM_LATEST = 'Skip offset from latest'; /** @@ -83,9 +82,8 @@ export class DatasourcesOverview { datasourceName: string, compactionConfig: CompactionConfig, ): Promise { - await this.openEditActions(datasourceName); + await this.openCompactionConfigurationDialog(datasourceName); - await this.page.click(`"${EDIT_COMPACTION_CONFIGURATION}"`); await setLabeledInput( this.page, SKIP_OFFSET_FROM_LATEST, @@ -96,10 +94,20 @@ export class DatasourcesOverview { await clickButton(this.page, 'Submit'); } - async getCompactionConfiguration(datasourceName: string): Promise { + private async openCompactionConfigurationDialog(datasourceName: string): Promise { await this.openEditActions(datasourceName); + await this.clickMenuItem('Edit compaction configuration'); + await this.page.waitForSelector('div.compaction-dialog'); + } + + private async clickMenuItem(text: string): Promise { + const menuItemSelector = `//a[*[contains(text(),"${text}")]]`; + await this.page.click(menuItemSelector); + } + + async getCompactionConfiguration(datasourceName: string): Promise { + await this.openCompactionConfigurationDialog(datasourceName); - await this.page.click(`"${EDIT_COMPACTION_CONFIGURATION}"`); const skipOffsetFromLatest = await getLabeledInput(this.page, SKIP_OFFSET_FROM_LATEST); const partitionsSpec = await readPartitionSpec(this.page); @@ -116,6 +124,23 @@ export class DatasourcesOverview { const editActions = await this.page.$$('span[icon=wrench]'); editActions[index].click(); + await this.waitForPopupMenu(); + } + + private async waitForPopupMenu(): Promise { + await this.page.waitFor(1000); // https://blueprintjs.com/docs/#core/components/popover.testing await this.page.waitFor('ul.bp3-menu'); } + + async triggerCompaction(): Promise { + await this.page.goto(this.baseUrl); + await this.clickMoreButton({ modifiers: ['Alt'] }); + await this.clickMenuItem('Force compaction run'); + await clickButton(this.page, 'Force compaction run'); + } + + private async clickMoreButton(options: any): Promise { + await this.page.click('//button[span[@icon="more"]]', options); + await this.waitForPopupMenu(); + } }