-
Notifications
You must be signed in to change notification settings - Fork 154
test(tracer): make e2e tests to follow the same convention in Logger and Metrics #788
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
Conversation
it('should have correct annotations and metadata', async () => { | ||
const tracesWhenAllFlagsEnabled = await getTraces(xray, startTime, await getFunctionArn(functionNameWithAllFlagsEnabled), invocations, 5); | ||
|
||
for (let i = 0; i < invocations; i++) { | ||
const trace = tracesWhenAllFlagsEnabled[i]; | ||
const invocationSubsegment = getInvocationSubsegment(trace); | ||
const handlerSubsegment = getFirstSubsegment(invocationSubsegment); | ||
const { annotations, metadata } = handlerSubsegment; | ||
|
||
const isColdStart = (i === 0); | ||
assertAnnotation({ | ||
annotations, | ||
isColdStart, | ||
expectedServiceName: serviceNameWithAllFlagsEnabled, | ||
expectedCustomAnnotationKey, | ||
expectedCustomAnnotationValue, | ||
}); | ||
|
||
if (!metadata) { | ||
fail('metadata is missing'); | ||
} | ||
expect(metadata[serviceNameWithAllFlagsEnabled][expectedCustomMetadataKey]) | ||
.toEqual(expectedCustomMetadataValue); | ||
|
||
const shouldThrowAnError = (i === (invocations - 1)); | ||
if (!shouldThrowAnError) { | ||
// Assert that the metadata object contains the response | ||
expect(metadata[serviceNameWithAllFlagsEnabled]['index.handler response']) | ||
.toEqual(expectedCustomResponseValue); | ||
} | ||
} | ||
}, TEST_CASE_TIMEOUT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I break this part out of the existing test case to make it not too long.
* 3. httpbin.org (Remote call) | ||
* 4. '### myMethod' (method decorator) | ||
*/ | ||
const handlerSubsegment = getFirstSubsegment(invocationSubsegment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of nested if
. I use a helper function to ensure that the item isn't null. The check to please TypeScript compilers are moved to the helper method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this, thanks for simplyfing that indentation hell that I got us in :D
const shouldThrowAnError = (i === (invocations - 1)); | ||
if (shouldThrowAnError) { | ||
// Assert that the subsegment has the expected fault | ||
expect(invocationSubsegment.error).toBe(true); | ||
expect(handlerSubsegment.error).toBe(true); | ||
// Assert that no error was captured on the subsegment | ||
expect(handlerSubsegment.hasOwnProperty('cause')).toBe(false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only unique part of this test case.
/** | ||
* Test tracer in middy setup | ||
* | ||
* @group e2e/tracer/middy | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost the same as decorator case. The only difference is that we do not captureMethod()
so we have 1 less custom trace.
import { | ||
generateUniqueName, | ||
isValidRuntimeKey, | ||
} from '@aws-lambda-powertools/commons/tests/utils/e2eUtils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra-nit: can we swap this import and the previous one so we have all the relative ones after the one from node_modules
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a mistake. I intend to import relatively, not from the package. (or we need to rebuild common for every change)
I'll change this (and other files) to relative import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one extra-minor comment about module import order but approving already since it's purely stylistic.
Really like the new test setup, a breadth of fresh air :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description of your changes
annotation
andmetadata
test out of the existing test casesHow to verify this change
Results (partial)
Related issues, RFCs
#497
#529
PR status
Is this ready for review?: YES
Is it a breaking change?: NO
Checklist
Breaking change checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.