Skip to content

Commit

Permalink
make unit tests run faster
Browse files Browse the repository at this point in the history
  • Loading branch information
jj22ee committed Aug 15, 2024
1 parent ce592e5 commit 7794f36
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 10 deletions.
150 changes: 150 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@aws-sdk/client-sns": "3.85.0",
"@aws-sdk/client-sqs": "3.85.0",
"@aws-sdk/types": "3.78.0",
"@smithy/node-http-handler": "3.1.4",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/contrib-test-utils": "^0.40.0",
"@opentelemetry/sdk-trace-base": "^1.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { AttributeNames } from '../src/enums';
registerInstrumentationTesting(new AwsInstrumentation());

import { Kinesis } from '@aws-sdk/client-kinesis';
import { NodeHttpHandler } from '@smithy/node-http-handler';
import * as AWS from 'aws-sdk';
import { AWSError } from 'aws-sdk';
import * as nock from 'nock';
Expand Down Expand Up @@ -88,6 +89,11 @@ describe('Kinesis - v3', () => {
accessKeyId: 'abcde',
secretAccessKey: 'abcde',
},
requestHandler: new NodeHttpHandler({
connectionTimeout: 10,
requestTimeout: 10,
socketTimeout: 10,
}),
});
});

Expand Down
29 changes: 19 additions & 10 deletions plugins/node/opentelemetry-instrumentation-aws-sdk/test/s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { AttributeNames } from '../src/enums';
registerInstrumentationTesting(new AwsInstrumentation());

import { S3 } from '@aws-sdk/client-s3';
import { NodeHttpHandler } from '@smithy/node-http-handler';
import * as AWS from 'aws-sdk';
import { AWSError } from 'aws-sdk';
import * as nock from 'nock';
Expand Down Expand Up @@ -86,33 +87,41 @@ describe('S3 - v3', () => {
accessKeyId: 'abcde',
secretAccessKey: 'abcde',
},
requestHandler: new NodeHttpHandler({
connectionTimeout: 10,
requestTimeout: 10,
socketAcquisitionWarningTimeout: 10,
socketTimeout: 10,
}),
});
});

describe('ListObjects', () => {
describe('GetObjectAttributes', () => {
it('adds bucket Name', async () => {
const dummyBucketName = 'dummy-bucket-name';

nock(`https://s3.${region}.amazonaws.com/`).post('/').reply(200, 'null');

await s3
.listObjects({
.getObjectAttributes({
Bucket: dummyBucketName,
Key: undefined,
ObjectAttributes: [],
})
.catch((err: any) => {});

const testSpans: ReadableSpan[] = getTestSpans();
const listObjectsSpans: ReadableSpan[] = testSpans.filter(
const getObjectAttributesSpans: ReadableSpan[] = testSpans.filter(
(s: ReadableSpan) => {
return s.name === 'S3.ListObjects';
return s.name === 'S3.GetObjectAttributes';
}
);
expect(listObjectsSpans.length).toBe(1);
const listObjectsSpan = listObjectsSpans[0];
expect(listObjectsSpan.attributes[AttributeNames.AWS_S3_BUCKET]).toBe(
dummyBucketName
);
expect(listObjectsSpan.kind).toBe(SpanKind.CLIENT);
expect(getObjectAttributesSpans.length).toBe(1);
const getObjectAttributesSpan = getObjectAttributesSpans[0];
expect(
getObjectAttributesSpan.attributes[AttributeNames.AWS_S3_BUCKET]
).toBe(dummyBucketName);
expect(getObjectAttributesSpan.kind).toBe(SpanKind.CLIENT);
});
});
});

0 comments on commit 7794f36

Please sign in to comment.