From 7794f3639bdddce9cdcb5dff41575b6d5c0d440f Mon Sep 17 00:00:00 2001 From: jjllee Date: Thu, 15 Aug 2024 11:36:22 -0700 Subject: [PATCH] make unit tests run faster --- package-lock.json | 150 ++++++++++++++++++ .../package.json | 1 + .../test/kinesis.test.ts | 6 + .../test/s3.test.ts | 29 ++-- 4 files changed, 176 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index c37653e5fd..c9f8bbf790 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38517,6 +38517,7 @@ "@opentelemetry/api": "^1.3.0", "@opentelemetry/contrib-test-utils": "^0.40.0", "@opentelemetry/sdk-trace-base": "^1.8.0", + "@smithy/node-http-handler": "3.1.4", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "@types/sinon": "10.0.18", @@ -38539,6 +38540,92 @@ "@opentelemetry/api": "^1.3.0" } }, + "plugins/node/opentelemetry-instrumentation-aws-sdk/node_modules/@smithy/abort-controller": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@smithy/abort-controller/-/abort-controller-3.1.1.tgz", + "integrity": "sha512-MBJBiidoe+0cTFhyxT8g+9g7CeVccLM0IOKKUMCNQ1CNMJ/eIfoo0RTfVrXOONEI1UCN1W+zkiHSbzUNE9dZtQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^3.3.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "plugins/node/opentelemetry-instrumentation-aws-sdk/node_modules/@smithy/node-http-handler": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-3.1.4.tgz", + "integrity": "sha512-+UmxgixgOr/yLsUxcEKGH0fMNVteJFGkmRltYFHnBMlogyFdpzn2CwqWmxOrfJELhV34v0WSlaqG1UtE1uXlJg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@smithy/abort-controller": "^3.1.1", + "@smithy/protocol-http": "^4.1.0", + "@smithy/querystring-builder": "^3.0.3", + "@smithy/types": "^3.3.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "plugins/node/opentelemetry-instrumentation-aws-sdk/node_modules/@smithy/protocol-http": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-4.1.0.tgz", + "integrity": "sha512-dPVoHYQ2wcHooGXg3LQisa1hH0e4y0pAddPMeeUPipI1tEOqL6A4N0/G7abeq+K8wrwSgjk4C0wnD1XZpJm5aA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^3.3.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "plugins/node/opentelemetry-instrumentation-aws-sdk/node_modules/@smithy/querystring-builder": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@smithy/querystring-builder/-/querystring-builder-3.0.3.tgz", + "integrity": "sha512-vyWckeUeesFKzCDaRwWLUA1Xym9McaA6XpFfAK5qI9DKJ4M33ooQGqvM4J+LalH4u/Dq9nFiC8U6Qn1qi0+9zw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^3.3.0", + "@smithy/util-uri-escape": "^3.0.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "plugins/node/opentelemetry-instrumentation-aws-sdk/node_modules/@smithy/types": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/@smithy/types/-/types-3.3.0.tgz", + "integrity": "sha512-IxvBBCTFDHbVoK7zIxqA1ZOdc4QfM5HM7rGleCuHi7L1wnKv5Pn69xXJQ9hgxH60ZVygH9/JG0jRgtUncE3QUA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "plugins/node/opentelemetry-instrumentation-aws-sdk/node_modules/@smithy/util-uri-escape": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@smithy/util-uri-escape/-/util-uri-escape-3.0.0.tgz", + "integrity": "sha512-LqR7qYLgZTD7nWLBecUi4aqolw8Mhza9ArpNEQ881MJJIU2sE5iHCK6TdyqqzcDLy0OPe10IY4T8ctVdtynubg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, "plugins/node/opentelemetry-instrumentation-aws-sdk/node_modules/@types/mocha": { "version": "8.2.3", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.3.tgz", @@ -51725,6 +51812,7 @@ "@opentelemetry/propagation-utils": "^0.30.10", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/semantic-conventions": "^1.22.0", + "@smithy/node-http-handler": "3.1.4", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "@types/sinon": "10.0.18", @@ -51741,6 +51829,68 @@ "typescript": "4.4.4" }, "dependencies": { + "@smithy/abort-controller": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@smithy/abort-controller/-/abort-controller-3.1.1.tgz", + "integrity": "sha512-MBJBiidoe+0cTFhyxT8g+9g7CeVccLM0IOKKUMCNQ1CNMJ/eIfoo0RTfVrXOONEI1UCN1W+zkiHSbzUNE9dZtQ==", + "dev": true, + "requires": { + "@smithy/types": "^3.3.0", + "tslib": "^2.6.2" + } + }, + "@smithy/node-http-handler": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-3.1.4.tgz", + "integrity": "sha512-+UmxgixgOr/yLsUxcEKGH0fMNVteJFGkmRltYFHnBMlogyFdpzn2CwqWmxOrfJELhV34v0WSlaqG1UtE1uXlJg==", + "dev": true, + "requires": { + "@smithy/abort-controller": "^3.1.1", + "@smithy/protocol-http": "^4.1.0", + "@smithy/querystring-builder": "^3.0.3", + "@smithy/types": "^3.3.0", + "tslib": "^2.6.2" + } + }, + "@smithy/protocol-http": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-4.1.0.tgz", + "integrity": "sha512-dPVoHYQ2wcHooGXg3LQisa1hH0e4y0pAddPMeeUPipI1tEOqL6A4N0/G7abeq+K8wrwSgjk4C0wnD1XZpJm5aA==", + "dev": true, + "requires": { + "@smithy/types": "^3.3.0", + "tslib": "^2.6.2" + } + }, + "@smithy/querystring-builder": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@smithy/querystring-builder/-/querystring-builder-3.0.3.tgz", + "integrity": "sha512-vyWckeUeesFKzCDaRwWLUA1Xym9McaA6XpFfAK5qI9DKJ4M33ooQGqvM4J+LalH4u/Dq9nFiC8U6Qn1qi0+9zw==", + "dev": true, + "requires": { + "@smithy/types": "^3.3.0", + "@smithy/util-uri-escape": "^3.0.0", + "tslib": "^2.6.2" + } + }, + "@smithy/types": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/@smithy/types/-/types-3.3.0.tgz", + "integrity": "sha512-IxvBBCTFDHbVoK7zIxqA1ZOdc4QfM5HM7rGleCuHi7L1wnKv5Pn69xXJQ9hgxH60ZVygH9/JG0jRgtUncE3QUA==", + "dev": true, + "requires": { + "tslib": "^2.6.2" + } + }, + "@smithy/util-uri-escape": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@smithy/util-uri-escape/-/util-uri-escape-3.0.0.tgz", + "integrity": "sha512-LqR7qYLgZTD7nWLBecUi4aqolw8Mhza9ArpNEQ881MJJIU2sE5iHCK6TdyqqzcDLy0OPe10IY4T8ctVdtynubg==", + "dev": true, + "requires": { + "tslib": "^2.6.2" + } + }, "@types/mocha": { "version": "8.2.3", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.3.tgz", diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json b/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json index f198a072ec..6b51d0c282 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json @@ -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", diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/kinesis.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/kinesis.test.ts index 626b811069..75f5c2954f 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/kinesis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/kinesis.test.ts @@ -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'; @@ -88,6 +89,11 @@ describe('Kinesis - v3', () => { accessKeyId: 'abcde', secretAccessKey: 'abcde', }, + requestHandler: new NodeHttpHandler({ + connectionTimeout: 10, + requestTimeout: 10, + socketTimeout: 10, + }), }); }); diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/s3.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/s3.test.ts index dc73c1b22b..c14299c500 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/s3.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/s3.test.ts @@ -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'; @@ -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); }); }); });