-
Notifications
You must be signed in to change notification settings - Fork 979
test(sdk-trace-base): ensure environment variables are cleaned up between tests #6011
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,14 +34,18 @@ describe('BasicTracerProvider - Node', () => { | |
| describe('constructor', () => { | ||
| describe('spanLimits', () => { | ||
| describe('when attribute value length limit is defined via env', () => { | ||
| afterEach(function () { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: when tests of this file are finished these env vars will be deleted but we are not certain if that was the env state before executing this file. following the spirit of this PR we could have a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review @david-luna. I'm fine with making whichever changes you want. I've noticed that environment variables in tests are handled inconsistently across the project (which is kind of expected in such a large project). For example:
Thoughts?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the examples you provided I think we should avoid the second option (deleting env vars at the end of the test). I also think the performance is not an issue but having to create a package or similar to share this logic across all packages for testing seems a bit overkill. A comment about it when there is a PR updating tests would gradually move the entire codebase to have the same approach regarding env. I'd say let's go for your option and review it in a while :) |
||
| delete process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT; | ||
| delete process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT; | ||
| }); | ||
|
|
||
| it('should have general attribute value length limits value as defined with env', () => { | ||
| process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = '115'; | ||
| const tracer = new BasicTracerProvider().getTracer( | ||
| 'default' | ||
| ) as Tracer; | ||
| const generalLimits = tracer.getGeneralLimits(); | ||
| assert.strictEqual(generalLimits.attributeValueLengthLimit, 115); | ||
| delete process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT; | ||
| }); | ||
| it('should have span attribute value length limit value same as general limit value', () => { | ||
| process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = '125'; | ||
|
|
@@ -52,7 +56,6 @@ describe('BasicTracerProvider - Node', () => { | |
| const spanLimits = tracer.getSpanLimits(); | ||
| assert.strictEqual(generalLimits.attributeValueLengthLimit, 125); | ||
| assert.strictEqual(spanLimits.attributeValueLengthLimit, 125); | ||
| delete process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT; | ||
| }); | ||
| it('should have span and general attribute value length limits as defined in env', () => { | ||
| process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = '125'; | ||
|
|
@@ -64,20 +67,22 @@ describe('BasicTracerProvider - Node', () => { | |
| const generalLimits = tracer.getGeneralLimits(); | ||
| assert.strictEqual(generalLimits.attributeValueLengthLimit, 125); | ||
| assert.strictEqual(spanLimits.attributeValueLengthLimit, 109); | ||
| delete process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT; | ||
| delete process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT; | ||
| }); | ||
| }); | ||
|
|
||
| describe('when attribute count limit is defined via env', () => { | ||
| afterEach(function () { | ||
| delete process.env.OTEL_ATTRIBUTE_COUNT_LIMIT; | ||
| delete process.env.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT; | ||
| }); | ||
|
|
||
| it('should general attribute count limit as defined with env', () => { | ||
| process.env.OTEL_ATTRIBUTE_COUNT_LIMIT = '25'; | ||
| const tracer = new BasicTracerProvider({}).getTracer( | ||
| 'default' | ||
| ) as Tracer; | ||
| const generalLimits = tracer.getGeneralLimits(); | ||
| assert.strictEqual(generalLimits.attributeCountLimit, 25); | ||
| delete process.env.OTEL_ATTRIBUTE_COUNT_LIMIT; | ||
| }); | ||
| it('should have span attribute count limit value same as general limit value', () => { | ||
| process.env.OTEL_ATTRIBUTE_COUNT_LIMIT = '20'; | ||
|
|
@@ -88,7 +93,6 @@ describe('BasicTracerProvider - Node', () => { | |
| const spanLimits = tracer.getSpanLimits(); | ||
| assert.strictEqual(generalLimits.attributeCountLimit, 20); | ||
| assert.strictEqual(spanLimits.attributeCountLimit, 20); | ||
| delete process.env.OTEL_ATTRIBUTE_COUNT_LIMIT; | ||
| }); | ||
| it('should have span and general attribute count limits as defined in env', () => { | ||
| process.env.OTEL_ATTRIBUTE_COUNT_LIMIT = '20'; | ||
|
|
@@ -100,8 +104,6 @@ describe('BasicTracerProvider - Node', () => { | |
| const generalLimits = tracer.getGeneralLimits(); | ||
| assert.strictEqual(generalLimits.attributeCountLimit, 20); | ||
| assert.strictEqual(spanLimits.attributeCountLimit, 35); | ||
| delete process.env.OTEL_ATTRIBUTE_COUNT_LIMIT; | ||
| delete process.env.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT; | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.