Skip to content

ref(tests): Refactor Node integration tests further. #5596

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

Merged
merged 7 commits into from
Aug 18, 2022

Conversation

onurtemizkan
Copy link
Collaborator

Following up: #5579

Apparently, the updates on #5579 were not enough to resolve leaking issues on #5512.

Debugging further, it seems that whenever a manual http request is initiated from a test (or test server) without waiting for / asserting on events or transactions, there are also transactions as side effects which may or may not finish before the test ends. This specifically happens with tests that assert request headers for trace and baggage, because they don't need to wait for the request / scenario to finish.

So it looks like the leakage to the next test doesn't come from the nock interceptor or an unclosed server, it comes from an unflushed Sentry transaction. The other tests using getEnvelopeRequest or getMultipleEnvelopeRequest finish wait for the events to be flushed.

While debugging this, I also made some more refactors in utilities, which I think will make them more concise.

Summary:

  • Making sure the events are flushed before tests that use getAPIResponse or runScenario complete.
  • Converted http usages in helpers to axios calls for simplicity and debuggability.
  • Moved nock initialization out of runServer so we don't need to carry nock.Scope around anymore. The nock instance is either manually initialized, or inside the getMultipleEnvelopeRequest function. The tests that are using manual http calls don't normally need nock anyways.
  • Filtering envelopes by their types on nock level, so if there is a need to filter them, we don't lose the expected count. Also, that makes the envelope indices inside tests simpler.
  • Switched to nock.cleanAll() and nock.removeInterceptor(mock) to end nock instead of .persist(false).

I have tested this locally on #5512 and it seems to be working well.
🤞

@onurtemizkan onurtemizkan self-assigned this Aug 17, 2022
@AbhiPrasad
Copy link
Member

@onurtemizkan - what do you think about trying to turn this into a class while we are here doing fixes? #5579 (review). If you think it adds too much complexity, no worries, we table it for later.

Also, happy to pair program on this any time! Just let me know :)

@onurtemizkan onurtemizkan force-pushed the onur/node-int-tests-refactor-flush branch from 7e25c6f to a065c41 Compare August 18, 2022 09:28
@onurtemizkan
Copy link
Collaborator Author

what do you think about trying to turn this into a class while we are here doing fixes? #5579 (review).

@AbhiPrasad, yes I was planning to include that, but would prefer if we do that on a clean scope after #5512 gets merged, if that's OK? I'm not entirely sure if there is still a potentially fragile test around.

@onurtemizkan onurtemizkan force-pushed the onur/node-int-tests-refactor-flush branch from 4e6adf3 to c47033f Compare August 18, 2022 10:11
@onurtemizkan onurtemizkan marked this pull request as ready for review August 18, 2022 10:11
@AbhiPrasad
Copy link
Member

yes I was planning to include that, but would prefer if we do that on a clean scope after #5512 gets merged, if that's OK

Sounds like a plan @onurtemizkan, lets do that!

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Nice - I think this is cleaner and easier to understand as well!

@AbhiPrasad AbhiPrasad enabled auto-merge (squash) August 18, 2022 13:58
@github-actions
Copy link
Contributor

github-actions bot commented Aug 18, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.41 KB (+0.03% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 60.06 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 17.98 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 52.92 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 19.77 KB (0%)
@sentry/browser - Webpack (minified) 64.31 KB (0%)
@sentry/react - Webpack (gzipped + minified) 19.79 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.71 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.92 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.29 KB (+0.01% 🔺)

@AbhiPrasad AbhiPrasad merged commit 8dd6743 into master Aug 18, 2022
@AbhiPrasad AbhiPrasad deleted the onur/node-int-tests-refactor-flush branch August 18, 2022 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants