Skip to content

Commit

Permalink
[APM] Fix flaky e2e’s (elastic#70790)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Jul 6, 2020
1 parent 8c08034 commit 7ee2680
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 221 deletions.
15 changes: 3 additions & 12 deletions x-pack/plugins/apm/e2e/cypress/integration/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@

/* eslint-disable import/no-extraneous-dependencies */

const RANGE_FROM = '2020-06-01T14:59:32.686Z';
const RANGE_TO = '2020-06-16T16:59:36.219Z';

const BASE_URL = Cypress.config().baseUrl;

/** The default time in ms to wait for a Cypress command to complete */
export const DEFAULT_TIMEOUT = 60 * 1000;

export function loginAndWaitForPage(
url: string,
dateRange?: { to: string; from: string }
dateRange: { to: string; from: string }
) {
const username = Cypress.env('elasticsearch_username');
const password = Cypress.env('elasticsearch_password');

cy.log(`Authenticating via ${username} / ${password}`);
let rangeFrom = RANGE_FROM;
let rangeTo = RANGE_TO;
if (dateRange) {
rangeFrom = dateRange.from;
rangeTo = dateRange.to;
}

const fullUrl = `${BASE_URL}${url}?rangeFrom=${rangeFrom}&rangeTo=${rangeTo}`;

const fullUrl = `${BASE_URL}${url}?rangeFrom=${dateRange.from}&rangeTo=${dateRange.to}`;
cy.visit(fullUrl, { auth: { username, password } });

cy.viewport('macbook-15');
Expand Down
9 changes: 1 addition & 8 deletions x-pack/plugins/apm/e2e/cypress/integration/snapshots.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
module.exports = {
"__version": "4.5.0",
"APM": {
"Transaction duration charts": {
"1": "55 ms",
"2": "28 ms",
"3": "0 ms"
}
},
"__version": "4.9.0",
"RUM Dashboard": {
"Client metrics": {
"1": "62 ",
Expand Down
14 changes: 8 additions & 6 deletions x-pack/plugins/apm/e2e/cypress/support/step_definitions/apm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const DEFAULT_TIMEOUT = 60 * 1000;

Given(`a user browses the APM UI application`, () => {
// open service overview page
loginAndWaitForPage(`/app/apm#/services`);
loginAndWaitForPage(`/app/apm#/services`, {
from: '2020-06-01T14:59:32.686Z',
to: '2020-06-16T16:59:36.219Z',
});
});

When(`the user inspects the opbeans-node service`, () => {
Expand All @@ -34,9 +37,8 @@ Then(`should have correct y-axis ticks`, () => {
// wait for all loading to finish
cy.get('kbnLoadingIndicator').should('not.be.visible');

cy.get(yAxisTick).eq(2).invoke('text').snapshot();

cy.get(yAxisTick).eq(1).invoke('text').snapshot();

cy.get(yAxisTick).eq(0).invoke('text').snapshot();
// literal assertions because snapshot() doesn't retry
cy.get(yAxisTick).eq(2).should('have.text', '55 ms');
cy.get(yAxisTick).eq(1).should('have.text', '28 ms');
cy.get(yAxisTick).eq(0).should('have.text', '0 ms');
});
18 changes: 9 additions & 9 deletions x-pack/plugins/apm/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
},
"dependencies": {
"@cypress/snapshot": "^2.1.3",
"@cypress/webpack-preprocessor": "^5.2.0",
"@cypress/webpack-preprocessor": "^5.4.1",
"@types/cypress-cucumber-preprocessor": "^1.14.1",
"@types/node": "^14.0.1",
"@types/node": "^14.0.14",
"axios": "^0.19.2",
"cypress": "^4.5.0",
"cypress-cucumber-preprocessor": "^2.3.1",
"cypress": "^4.9.0",
"cypress-cucumber-preprocessor": "^2.5.2",
"ora": "^4.0.4",
"p-limit": "^2.3.0",
"p-limit": "^3.0.1",
"p-retry": "^4.2.0",
"ts-loader": "^7.0.4",
"typescript": "3.9.5",
"wait-on": "^5.0.0",
"ts-loader": "^7.0.5",
"typescript": "3.9.6",
"wait-on": "^5.0.1",
"webpack": "^4.43.0",
"yargs": "^15.3.1"
"yargs": "^15.4.0"
}
}
10 changes: 6 additions & 4 deletions x-pack/plugins/apm/e2e/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,20 @@ yarn &> ${TMP_DIR}/e2e-yarn.log
echo "" # newline
echo "${bold}Static mock data (logs: ${E2E_DIR}${TMP_DIR}/ingest-data.log)${normal}"

STATIC_MOCK_FILENAME='2020-06-12.json'

# Download static data if not already done
if [ ! -e "${TMP_DIR}/events.json" ]; then
echo 'Downloading events.json...'
curl --silent https://storage.googleapis.com/apm-ui-e2e-static-data/2020-06-12.json --output ${TMP_DIR}/events.json
if [ ! -e "${TMP_DIR}/${STATIC_MOCK_FILENAME}" ]; then
echo "Downloading ${STATIC_MOCK_FILENAME}..."
curl --silent https://storage.googleapis.com/apm-ui-e2e-static-data/${STATIC_MOCK_FILENAME} --output ${TMP_DIR}/${STATIC_MOCK_FILENAME}
fi

# echo "Deleting existing indices (apm* and .apm*)"
curl --silent --user admin:changeme -XDELETE "localhost:${ELASTICSEARCH_PORT}/.apm*" > /dev/null
curl --silent --user admin:changeme -XDELETE "localhost:${ELASTICSEARCH_PORT}/apm*" > /dev/null

# Ingest data into APM Server
node ingest-data/replay.js --server-url http://localhost:$APM_SERVER_PORT --events ${TMP_DIR}/events.json 2>> ${TMP_DIR}/ingest-data.log
node ingest-data/replay.js --server-url http://localhost:$APM_SERVER_PORT --events ${TMP_DIR}/${STATIC_MOCK_FILENAME} 2>> ${TMP_DIR}/ingest-data.log

# Abort if not all events were ingested correctly
if [ $? -ne 0 ]; then
Expand Down
Loading

0 comments on commit 7ee2680

Please sign in to comment.