Skip to content

Commit 382dbaa

Browse files
committed
fix/troubleshooting
1 parent 46b769b commit 382dbaa

File tree

1 file changed

+61
-19
lines changed

1 file changed

+61
-19
lines changed

packages/tracing/tests/e2e/tracer.test.ts

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,25 @@ describe('Tracer integration tests', () => {
154154
// Assert that there are three subsegments
155155
expect(handlerSubsegment?.subsegments?.length).toBe(3);
156156

157-
const [ AWSSDKSubsegment1, AWSSDKSubsegment2, HTTPSegment ] = handlerSubsegment?.subsegments;
158-
// Assert that the subsegment names are the expected ones
159-
expect(AWSSDKSubsegment1.name).toBe('DynamoDB');
160-
expect(AWSSDKSubsegment2.name).toBe('DynamoDB');
161-
expect(HTTPSegment.name).toBe('httpbin.org');
157+
// Sort the subsegments by name
158+
const dynamoDBSubsegments: ParsedDocument[] = [];
159+
const httpSubsegment: ParsedDocument[] = [];
160+
const otherSegments: ParsedDocument[] = [];
161+
handlerSubsegment?.subsegments.forEach(subsegment => {
162+
if (subsegment.name === 'DynamoDB') {
163+
dynamoDBSubsegments.push(subsegment);
164+
} else if (subsegment.name === 'httpbin.org') {
165+
httpSubsegment.push(subsegment);
166+
} else {
167+
otherSegments.push(subsegment);
168+
}
169+
});
170+
// Assert that there are exactly two subsegment with the name 'DynamoDB'
171+
expect(dynamoDBSubsegments.length).toBe(2);
172+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
173+
expect(httpSubsegment.length).toBe(1);
174+
// Assert that there are exactly zero other subsegments
175+
expect(otherSegments.length).toBe(0);
162176

163177
const { annotations, metadata } = handlerSubsegment;
164178

@@ -225,11 +239,25 @@ describe('Tracer integration tests', () => {
225239
// Assert that there're two subsegments
226240
expect(handlerSubsegment?.subsegments?.length).toBe(3);
227241

228-
const [ AWSSDKSubsegment1, AWSSDKSubsegment2, HTTPSegment ] = handlerSubsegment?.subsegments;
229-
// Assert that the subsegment names is the expected ones
230-
expect(AWSSDKSubsegment1.name).toBe('DynamoDB');
231-
expect(AWSSDKSubsegment2.name).toBe('DynamoDB');
232-
expect(HTTPSegment.name).toBe('httpbin.org');
242+
// Sort the subsegments by name
243+
const dynamoDBSubsegments: ParsedDocument[] = [];
244+
const httpSubsegment: ParsedDocument[] = [];
245+
const otherSegments: ParsedDocument[] = [];
246+
handlerSubsegment?.subsegments.forEach(subsegment => {
247+
if (subsegment.name === 'DynamoDB') {
248+
dynamoDBSubsegments.push(subsegment);
249+
} else if (subsegment.name === 'httpbin.org') {
250+
httpSubsegment.push(subsegment);
251+
} else {
252+
otherSegments.push(subsegment);
253+
}
254+
});
255+
// Assert that there are exactly two subsegment with the name 'DynamoDB'
256+
expect(dynamoDBSubsegments.length).toBe(2);
257+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
258+
expect(httpSubsegment.length).toBe(1);
259+
// Assert that there are exactly zero other subsegments
260+
expect(otherSegments.length).toBe(0);
233261

234262
const { annotations, metadata } = handlerSubsegment;
235263

@@ -296,11 +324,25 @@ describe('Tracer integration tests', () => {
296324
// Assert that there're two subsegments
297325
expect(handlerSubsegment?.subsegments?.length).toBe(3);
298326

299-
const [ AWSSDKSubsegment1, AWSSDKSubsegment2, HTTPSegment ] = handlerSubsegment?.subsegments;
300-
// Assert that the subsegment names are the expected ones
301-
expect(AWSSDKSubsegment1.name).toBe('DynamoDB');
302-
expect(AWSSDKSubsegment2.name).toBe('DynamoDB');
303-
expect(HTTPSegment.name).toBe('httpbin.org');
327+
// Sort the subsegments by name
328+
const dynamoDBSubsegments: ParsedDocument[] = [];
329+
const httpSubsegment: ParsedDocument[] = [];
330+
const otherSegments: ParsedDocument[] = [];
331+
handlerSubsegment?.subsegments.forEach(subsegment => {
332+
if (subsegment.name === 'DynamoDB') {
333+
dynamoDBSubsegments.push(subsegment);
334+
} else if (subsegment.name === 'httpbin.org') {
335+
httpSubsegment.push(subsegment);
336+
} else {
337+
otherSegments.push(subsegment);
338+
}
339+
});
340+
// Assert that there are exactly two subsegment with the name 'DynamoDB'
341+
expect(dynamoDBSubsegments.length).toBe(2);
342+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
343+
expect(httpSubsegment.length).toBe(1);
344+
// Assert that there are exactly zero other subsegments
345+
expect(otherSegments.length).toBe(0);
304346

305347
const { annotations, metadata } = handlerSubsegment;
306348

@@ -387,7 +429,7 @@ describe('Tracer integration tests', () => {
387429
// Assert that the subsegment name is the expected one
388430
expect(handlerSubsegment.name).toBe('## index.handler');
389431
if (handlerSubsegment?.subsegments !== undefined) {
390-
// Assert that there're three subsegments
432+
// Assert that there are four subsegments
391433
expect(handlerSubsegment?.subsegments?.length).toBe(4);
392434

393435
// Sort the subsegments by name
@@ -489,7 +531,7 @@ describe('Tracer integration tests', () => {
489531
// Assert that the subsegment name is the expected one
490532
expect(handlerSubsegment.name).toBe('## index.handler');
491533
if (handlerSubsegment?.subsegments !== undefined) {
492-
// Assert that there're three subsegments
534+
// Assert that there are four subsegments
493535
expect(handlerSubsegment?.subsegments?.length).toBe(4);
494536

495537
// Sort the subsegments by name
@@ -591,8 +633,8 @@ describe('Tracer integration tests', () => {
591633
// Assert that the subsegment name is the expected one
592634
expect(handlerSubsegment.name).toBe('## index.handler');
593635
if (handlerSubsegment?.subsegments !== undefined) {
594-
// Assert that there're three subsegments
595-
expect(handlerSubsegment?.subsegments?.length).toBe(5);
636+
// Assert that there are four subsegments
637+
expect(handlerSubsegment?.subsegments?.length).toBe(4);
596638

597639
// Sort the subsegments by name
598640
const dynamoDBSubsegments: ParsedDocument[] = [];

0 commit comments

Comments
 (0)