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

[APM] Fix broken unit tests #161636

Merged
merged 1 commit into from
Jul 12, 2023
Merged

Conversation

sorenlouv
Copy link
Member

@sorenlouv sorenlouv commented Jul 11, 2023

A bunch of APM unit tests were passing on CI but failing locally. This PR fixes the unit tests

Why fail locally and pass on CI??
The reason they pass on CI is because console.* is disabled on CI:

// on CI these logs just muddy up the console and produce a ton of unnecessary noise
console.log = () => {};
console.error = () => {};
console.warn = () => {};

Whereas in the APM jest config console.error is treated as a test failure:

jest.spyOn(console, 'error').mockImplementation((message, ...args) => {
console.log(message, ...args);
throw new Error(message);
});

@sorenlouv sorenlouv requested a review from a team as a code owner July 11, 2023 10:40
@botelastic botelastic bot added the Team:APM All issues that need APM UI Team support label Jul 11, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:APM)

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@sorenlouv sorenlouv added v8.9.0 release_note:skip Skip the PR/issue when compiling release notes labels Jul 11, 2023
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 409 413 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 488 492 +4
total +6

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@gbamparop
Copy link
Contributor

Thanks for fixing this! Can we have the configs aligned to prevent this from happening in the future?

@sorenlouv sorenlouv enabled auto-merge (squash) July 12, 2023 11:53
@sorenlouv
Copy link
Member Author

sorenlouv commented Jul 12, 2023

Can we have the configs aligned to prevent this from happening in the future?

Maybe. console.* is disabled globally on CI so we'd either have to enable it for everyone or find a way to only enable it for APM:

// on CI these logs just muddy up the console and produce a ton of unnecessary noise
console.log = () => {};
console.error = () => {};
console.warn = () => {};

Either way, I don't think that should block this PR.

@gbamparop
Copy link
Contributor

Can we have the configs aligned to prevent this from happening in the future?

Maybe. console.* is disabled globally on CI so we'd either have to enable it for everyone or find a way to only enable it for APM:

// on CI these logs just muddy up the console and produce a ton of unnecessary noise
console.log = () => {};
console.error = () => {};
console.warn = () => {};

Either way, I don't think that should block this PR.

Agree, shouldn't block the PR. An alternative is to remove our difference in the jest config.

Copy link
Contributor

@gbamparop gbamparop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sorenlouv sorenlouv merged commit ccb36d9 into elastic:main Jul 12, 2023
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 12, 2023
A bunch of APM unit tests were passing on CI but failing locally. This
PR fixes the unit tests

**Why fail locally and pass on CI??**
The reason they pass on CI is because `console.error` calls are omitted.
In the APM jest config `console.error` is treated as a test failure:

https://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15
(cherry picked from commit ccb36d9)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.9

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jul 12, 2023
# Backport

This will backport the following commits from `main` to `8.9`:
- [[APM] Fix broken unit tests
(#161636)](#161636)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-07-12T15:19:00Z","message":"[APM]
Fix broken unit tests (#161636)\n\nA bunch of APM unit tests were
passing on CI but failing locally. This\r\nPR fixes the unit
tests\r\n\r\n**Why fail locally and pass on CI??**\r\nThe reason they
pass on CI is because `console.error` calls are omitted.\r\nIn the APM
jest config `console.error` is treated as a test
failure:\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15","sha":"ccb36d929a2514dfce82534471455480e335e206","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:APM","release_note:skip","v8.9.0","v8.10.0"],"number":161636,"url":"https://github.com/elastic/kibana/pull/161636","mergeCommit":{"message":"[APM]
Fix broken unit tests (#161636)\n\nA bunch of APM unit tests were
passing on CI but failing locally. This\r\nPR fixes the unit
tests\r\n\r\n**Why fail locally and pass on CI??**\r\nThe reason they
pass on CI is because `console.error` calls are omitted.\r\nIn the APM
jest config `console.error` is treated as a test
failure:\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15","sha":"ccb36d929a2514dfce82534471455480e335e206"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161636","number":161636,"mergeCommit":{"message":"[APM]
Fix broken unit tests (#161636)\n\nA bunch of APM unit tests were
passing on CI but failing locally. This\r\nPR fixes the unit
tests\r\n\r\n**Why fail locally and pass on CI??**\r\nThe reason they
pass on CI is because `console.error` calls are omitted.\r\nIn the APM
jest config `console.error` is treated as a test
failure:\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15","sha":"ccb36d929a2514dfce82534471455480e335e206"}}]}]
BACKPORT-->

Co-authored-by: Søren Louv-Jansen <[email protected]>
@sorenlouv sorenlouv deleted the fix-broken-unit-tests branch July 13, 2023 12:13
sorenlouv added a commit that referenced this pull request Jul 18, 2023
#161636 fixed a couple of unit
tests that were failing locally but passing on CI. This PR should
prevent this from happening again.

**Why they failed locally and not on CI??**
Locally `console.error` is treated as a test failure:

https://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15

Whereas on CI `console.*` is disabled:

https://github.com/elastic/kibana/blob/a78c7b02b3b825826f39289e91e545ee6f4a67d9/packages/kbn-test/src/jest/setup/disable_console_logs.js#L9-L12

This means that if a test logs `console.error` it would fail locally but
not on CI. This PR changes that so console.error will not cause unit
tests to fail anywhere.
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 18, 2023
…ic#161959)

elastic#161636 fixed a couple of unit
tests that were failing locally but passing on CI. This PR should
prevent this from happening again.

**Why they failed locally and not on CI??**
Locally `console.error` is treated as a test failure:

https://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15

Whereas on CI `console.*` is disabled:

https://github.com/elastic/kibana/blob/a78c7b02b3b825826f39289e91e545ee6f4a67d9/packages/kbn-test/src/jest/setup/disable_console_logs.js#L9-L12

This means that if a test logs `console.error` it would fail locally but
not on CI. This PR changes that so console.error will not cause unit
tests to fail anywhere.

(cherry picked from commit c842479)
kibanamachine added a commit that referenced this pull request Jul 18, 2023
…161959) (#162100)

# Backport

This will backport the following commits from `main` to `8.9`:
- [[APM] Prevent console.error causing unit tests to fail locally
(#161959)](#161959)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Søren
Louv-Jansen","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-07-18T00:45:58Z","message":"[APM]
Prevent console.error causing unit tests to fail locally
(#161959)\n\nhttps://github.com//pull/161636 fixed a
couple of unit\r\ntests that were failing locally but passing on CI.
This PR should\r\nprevent this from happening again.\r\n\r\n**Why they
failed locally and not on CI??**\r\nLocally `console.error` is treated
as a test
failure:\r\n\r\nhttps://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15\r\n\r\nWhereas
on CI `console.*` is
disabled:\r\n\r\nhttps://github.com/elastic/kibana/blob/a78c7b02b3b825826f39289e91e545ee6f4a67d9/packages/kbn-test/src/jest/setup/disable_console_logs.js#L9-L12\r\n\r\nThis
means that if a test logs `console.error` it would fail locally
but\r\nnot on CI. This PR changes that so console.error will not cause
unit\r\ntests to fail
anywhere.","sha":"c842479d633ee28ddda3ce960e1341f20d5801e3","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:APM","release_note:skip","v8.9.0","v8.10.0"],"number":161959,"url":"https://github.com/elastic/kibana/pull/161959","mergeCommit":{"message":"[APM]
Prevent console.error causing unit tests to fail locally
(#161959)\n\nhttps://github.com//pull/161636 fixed a
couple of unit\r\ntests that were failing locally but passing on CI.
This PR should\r\nprevent this from happening again.\r\n\r\n**Why they
failed locally and not on CI??**\r\nLocally `console.error` is treated
as a test
failure:\r\n\r\nhttps://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15\r\n\r\nWhereas
on CI `console.*` is
disabled:\r\n\r\nhttps://github.com/elastic/kibana/blob/a78c7b02b3b825826f39289e91e545ee6f4a67d9/packages/kbn-test/src/jest/setup/disable_console_logs.js#L9-L12\r\n\r\nThis
means that if a test logs `console.error` it would fail locally
but\r\nnot on CI. This PR changes that so console.error will not cause
unit\r\ntests to fail
anywhere.","sha":"c842479d633ee28ddda3ce960e1341f20d5801e3"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161959","number":161959,"mergeCommit":{"message":"[APM]
Prevent console.error causing unit tests to fail locally
(#161959)\n\nhttps://github.com//pull/161636 fixed a
couple of unit\r\ntests that were failing locally but passing on CI.
This PR should\r\nprevent this from happening again.\r\n\r\n**Why they
failed locally and not on CI??**\r\nLocally `console.error` is treated
as a test
failure:\r\n\r\nhttps://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15\r\n\r\nWhereas
on CI `console.*` is
disabled:\r\n\r\nhttps://github.com/elastic/kibana/blob/a78c7b02b3b825826f39289e91e545ee6f4a67d9/packages/kbn-test/src/jest/setup/disable_console_logs.js#L9-L12\r\n\r\nThis
means that if a test logs `console.error` it would fail locally
but\r\nnot on CI. This PR changes that so console.error will not cause
unit\r\ntests to fail
anywhere.","sha":"c842479d633ee28ddda3ce960e1341f20d5801e3"}}]}]
BACKPORT-->

Co-authored-by: Søren Louv-Jansen <[email protected]>
ThomThomson pushed a commit to ThomThomson/kibana that referenced this pull request Aug 1, 2023
…ic#161959)

elastic#161636 fixed a couple of unit
tests that were failing locally but passing on CI. This PR should
prevent this from happening again.

**Why they failed locally and not on CI??**
Locally `console.error` is treated as a test failure:

https://github.com/elastic/kibana/blob/7ea0dd6b116a93024d68ea2d93fa4ce90e9bf189/x-pack/plugins/apm/jest_setup.js#L12-L15

Whereas on CI `console.*` is disabled:

https://github.com/elastic/kibana/blob/a78c7b02b3b825826f39289e91e545ee6f4a67d9/packages/kbn-test/src/jest/setup/disable_console_logs.js#L9-L12

This means that if a test logs `console.error` it would fail locally but
not on CI. This PR changes that so console.error will not cause unit
tests to fail anywhere.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support v8.9.0 v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants