Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs Explorer] Fix flaky test - Number of installed integrations do not match #188723

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const initialPackageMap = {
aws: 'AWS',
system: 'System',
};
const initialPackagesTexts = Object.values(initialPackageMap);

const expectedDataViews = ['logs-*', 'logstash-*', 'metrics-*'];
const sortedExpectedDataViews = expectedDataViews.slice().sort();
Expand Down Expand Up @@ -181,13 +180,20 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

describe('with installed integrations and uncategorized data streams', () => {
let cleanupIntegrationsSetup: () => Promise<void>;
let installedPackagesTexts: string[];

before(async () => {
await esArchiver.load(
'x-pack/test/functional/es_archives/observability_logs_explorer/data_streams'
);
cleanupIntegrationsSetup =
await PageObjects.observabilityLogsExplorer.setupInitialIntegrations();

const installedPackagesResponse =
await PageObjects.observabilityLogsExplorer.getInstalledPackages();
installedPackagesTexts = installedPackagesResponse.body.items.map(
({ title }: { title: string }) => title
);
});

after(async () => {
Expand All @@ -210,8 +216,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('should display a list of installed integrations', async () => {
const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations();

expect(integrations.length).to.be(3);
expect(integrations).to.eql(initialPackagesTexts);
expect(integrations.length).to.be(installedPackagesTexts.length);
expect(integrations).to.eql(installedPackagesTexts);
});

it('should sort the integrations list by the clicked sorting option', async () => {
Expand All @@ -220,39 +226,41 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

await retry.try(async () => {
const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(integrations).to.eql(initialPackagesTexts);
expect(integrations).to.eql(installedPackagesTexts);
});

// Test descending order
await PageObjects.observabilityLogsExplorer.clickSortButtonBy('desc');

await retry.try(async () => {
const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(integrations).to.eql(initialPackagesTexts.slice().reverse());
expect(integrations).to.eql(installedPackagesTexts.slice().reverse());
});

// Test back ascending order
await PageObjects.observabilityLogsExplorer.clickSortButtonBy('asc');

await retry.try(async () => {
const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(integrations).to.eql(initialPackagesTexts);
expect(integrations).to.eql(installedPackagesTexts);
});
});

it('should filter the integrations list by the typed integration name', async () => {
await PageObjects.observabilityLogsExplorer.typeSearchFieldWith('system');
const lastPackageText = installedPackagesTexts[installedPackagesTexts.length - 1];
const searchTerm = lastPackageText.split(' ')[0].toLowerCase();
await PageObjects.observabilityLogsExplorer.typeSearchFieldWith(searchTerm);

await retry.try(async () => {
const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(integrations).to.eql([initialPackageMap.system]);
expect(integrations).to.eql([lastPackageText]);
});

await PageObjects.observabilityLogsExplorer.typeSearchFieldWith('a');

await retry.try(async () => {
const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(integrations).to.eql([initialPackageMap.apache, initialPackageMap.aws]);
expect(integrations).to.eql(installedPackagesTexts.filter((p) => /^a/i.test(p)));
});
});

Expand All @@ -275,33 +283,50 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.observabilityLogsExplorer.setupAdditionalIntegrations();
await browser.refresh();

const installedPackagesResponse =
await PageObjects.observabilityLogsExplorer.getInstalledPackages();
installedPackagesTexts = installedPackagesResponse.body.items.map(
({ title }: { title: string }) => title
);

await PageObjects.observabilityLogsExplorer.openDataSourceSelector();

// Initially fetched integrations
await retry.try(async () => {
const { nodes } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(nodes.length).to.be(15);
expect(nodes.length).to.be(Math.min(15, installedPackagesTexts.length));
await nodes.at(-1)?.scrollIntoView();
});

// Load more integrations
await retry.try(async () => {
const { nodes } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(nodes.length).to.be(20);
expect(nodes.length).to.be(Math.min(20, installedPackagesTexts.length));
await nodes.at(-1)?.scrollIntoView();
});

// No other integrations to load after scrolling to last integration
await retry.try(async () => {
const { nodes } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(nodes.length).to.be(20);
expect(nodes.length).to.be(installedPackagesTexts.length);
});

await cleanupAdditionalSetup();
});

describe('clicking on integration and moving into the second navigation level', () => {
before(async () => {
describe('clicking on Apache HTTP Server integration and moving into the second navigation level', () => {
before(async function () {
const installedPackagesResponse =
await PageObjects.observabilityLogsExplorer.getInstalledPackages();
installedPackagesTexts = installedPackagesResponse.body.items.map(
({ title }: { title: string }) => title
);

// Skip the suite if Apache HTTP Server integration is not available
if (!installedPackagesTexts.includes(initialPackageMap.apache)) {
this.skip();
}

await PageObjects.observabilityLogsExplorer.navigateTo();
});

Expand All @@ -312,8 +337,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('should display a list of available datasets', async () => {
await retry.try(async () => {
const { nodes } = await PageObjects.observabilityLogsExplorer.getIntegrations();
await nodes[0].click();
const { nodes, integrations } =
await PageObjects.observabilityLogsExplorer.getIntegrations();
const apacheIntegrationIndex = integrations.indexOf(initialPackageMap.apache);
await nodes[apacheIntegrationIndex].click();
});

await retry.try(async () => {
Expand Down Expand Up @@ -779,6 +806,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

describe('when open/close the selector', () => {
before(async () => {
const installedPackagesResponse =
await PageObjects.observabilityLogsExplorer.getInstalledPackages();
installedPackagesTexts = installedPackagesResponse.body.items.map(
({ title }: { title: string }) => title
);

await PageObjects.observabilityLogsExplorer.navigateTo();
});

Expand All @@ -787,10 +820,17 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.observabilityLogsExplorer.openDataSourceSelector();
});

it('should restore the latest navigation panel', async () => {
it('should restore the latest navigation panel', async function () {
// Skip the test if Apache HTTP Server integration is not installed
if (!installedPackagesTexts.includes(initialPackageMap.apache)) {
this.skip();
}

await retry.try(async () => {
const { nodes } = await PageObjects.observabilityLogsExplorer.getIntegrations();
await nodes[0].click();
const { nodes, integrations } =
await PageObjects.observabilityLogsExplorer.getIntegrations();
const apacheIntegrationIndex = integrations.indexOf(initialPackageMap.apache);
await nodes[apacheIntegrationIndex].click();
});

await retry.try(async () => {
Expand Down Expand Up @@ -828,33 +868,46 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('should restore the latest search results', async () => {
await PageObjects.observabilityLogsExplorer.typeSearchFieldWith('system');
const lastPackageText = installedPackagesTexts[installedPackagesTexts.length - 1];
const searchTerm = lastPackageText.split(' ')[0].toLowerCase();
await PageObjects.observabilityLogsExplorer.typeSearchFieldWith(searchTerm);

await retry.try(async () => {
const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(integrations).to.eql([initialPackageMap.system]);
expect(integrations).to.eql([lastPackageText]);
});

await PageObjects.observabilityLogsExplorer.closeDataSourceSelector();
await PageObjects.observabilityLogsExplorer.openDataSourceSelector();

await retry.try(async () => {
const { integrations } = await PageObjects.observabilityLogsExplorer.getIntegrations();
expect(integrations).to.eql([initialPackageMap.system]);
expect(integrations).to.eql([lastPackageText]);
});
});
});

describe('when switching between tabs or integration panels', () => {
before(async () => {
before(async function () {
const installedPackagesResponse =
await PageObjects.observabilityLogsExplorer.getInstalledPackages();
installedPackagesTexts = installedPackagesResponse.body.items.map(
({ title }: { title: string }) => title
);

// Skip the suite if Apache Http Server integration is not installed
if (!installedPackagesTexts.includes(initialPackageMap.apache)) {
this.skip();
}

await PageObjects.observabilityLogsExplorer.navigateTo();
});

it('should remember the latest search and restore its results', async () => {
await PageObjects.observabilityLogsExplorer.openDataSourceSelector();
await PageObjects.observabilityLogsExplorer.clearSearchField();

await PageObjects.observabilityLogsExplorer.typeSearchFieldWith('apache');
await PageObjects.observabilityLogsExplorer.typeSearchFieldWith('apache http');

await retry.try(async () => {
const { nodes, integrations } =
Expand Down Expand Up @@ -905,7 +958,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(integrations).to.eql([initialPackageMap.apache]);

const searchValue = await PageObjects.observabilityLogsExplorer.getSearchFieldValue();
expect(searchValue).to.eql('apache');
expect(searchValue).to.eql('apache http');

nodes[0].click();
});
Expand Down
Loading