Skip to content
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

test: add 'test-services' system for running tests locally with requisite services in Docker #2214

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-all-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
RUN_MONGODB_TESTS: 1
RUN_MONGODB_TESTS: "true"
RUN_MSSQL_TESTS: 1
RUN_MYSQL_TESTS: 1
RUN_POSTGRES_TESTS: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
env:
RUN_CASSANDRA_TESTS: 1
RUN_MEMCACHED_TESTS: 1
RUN_MONGODB_TESTS: 1
RUN_MONGODB_TESTS: "true"
RUN_MYSQL_TESTS: 1
RUN_MSSQL_TESTS: 1
RUN_POSTGRES_TESTS: 1
Expand Down
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ The conventional commit type (in PR title) is very important to automatically bu

There is no need to update the CHANGELOG in a PR because it will be updated as part of the release process (see [RELEASING.md](RELEASING.md) for more details).

### Testing

Most unit tests case be run via:

```sh
npm test
```

However, some instrumentations require test-services to be running (e.g. the `instrumentation-mongodb` package requires a MongoDB server). Use the `test-services`-related npm scripts to start test services in Docker and then run the tests with the appropriate configuration to use those services:

```sh
npm run test-services:start # starts services in Docker
npm run test:with-test-services # runs 'npm test' with envvars from test/test-services.env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this command more about telling to use the env variables from the file you mentioned or does it also check if the required services are running?
Just thinking if make sense to combine this, and only call run test:with-test-services which will start the service and use the correspondent vars

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm run test:with-test-services just sets the envvars and then runs the tests.

Just thinking if make sense to combine this, and only call run test:with-test-services which will start the service and use the correspondent vars

The value in having test-services:start and test:with-test-services be separate commands is to support a dev/test cycle where one is repeatedly running the tests. It would be a time suck to start and stop services for each test run.

Or, if you are proposing that this new npm run test:and-start-services-if-necessary thing (it wouldn't have to be that awful long name :) would only start services if necessary and then run tests then:

  • Yes, that would avoid the time burden of starting and stopping test services for each run.
  • However, it creates an slight DX imbalance in that one still needs another script to stop any started test-services. Perhaps it is just a personal preference thing. I like the matching of test-services:start and test-services:end.
  • Also, FWIW, npm run test-services:{start,end} support arguments do the underlying docker compose ... call. So, if one is just working on the redis tests, then one can npm run test-services:start -- redis. This is relatively minor though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I agree that without reading the developer guide docs that npm run test:with-test-services does potentially give the impression that it'll handle starting the test services for the developer. npm run test:and-assume-test-services-are-running-cuz-imma-use-them is a little long.

Copy link
Contributor

@maryliag maryliag Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was indeed thinking of keeping the end separate. It was just that the start seems to be a requirement for the with-test-services, so it would make sense to have them as one, since you would always run them together. I didn't think about the case where you would start but not necessarily use the with-test-services after, so make sense to have the start separate.
It would be nice if the with-test-services could start the service in case you have forgotten to start, but that could be some future improvement. I wouldn't hold any approval based on this 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm run test:just-run-all-the-things

npm run test-services:stop # stops Docker containers
```

Use this set of commands in the top-level directory to test all packages, or
in a specific package directory that requires a test service (e.g. `plugins/node/opentelemetry-instrumentation-mongodb`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
in a specific package directory that requires a test service (e.g. `plugins/node/opentelemetry-instrumentation-mongodb`).
in a specific package directory to test only that specific package (e.g. `plugins/node/opentelemetry-instrumentation-mongodb`), regardless if the tests need a test service.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regardless if the tests need a test service.

Actually that wasn't my intent. Packages that have no dep on a test-service won't typically have the npm run test:with-test-services script.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, the wording made me think that was the case, meaning I thought the set of commands was referring to the start -> with-test-services -> stop, but I guess by set you meant the group of 3 AND the npm start. Can you make this more clear? So something along the lines of:

The first option can be used in the top-level directory to test all packages, 
while the second option can be executed from specific package directory that 
requires a test service.

And also add some clarification as:

if you run the first option from the top-level, the tests with required services will
(or will not? I'm not clear about that, so the clarification will definitely help here hehe) 
start their required services and be executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, now I'm confused. :) I was attempting to say that running all three of

npm run test-services:start     # starts services in Docker
npm run test:with-test-services # runs 'npm test' with envvars from test/test-services.env
npm run test-services:stop      # stops Docker containers

works if one is in the top-directory of the git clone. And they also work if cd'd into a specific package of the monorepo if, say, you are doing development just on that package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, so it needs some rewording, I was confused 😅


### Benchmarks

When two or more approaches must be compared, please write a benchmark in the benchmark/index.js module so that we can keep track of the most efficient algorithm.
Expand Down
33 changes: 26 additions & 7 deletions package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"test:ci:changed": "lerna run test --since origin/main",
"test:browser": "lerna run test:browser --concurrency 1",
"test-all-versions": "npm run --if-present --workspaces test-all-versions",
"test-services:start": "docker compose -f ./test/docker-compose.yaml up -d --wait",
"test-services:stop": "docker compose -f ./test/docker-compose.yaml down",
"test:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=./test/test-services.env npm test",
"bump": "lerna publish",
"changelog": "lerna-changelog",
"lint": "lerna run lint",
Expand All @@ -44,6 +47,7 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "5.8.1",
"@typescript-eslint/parser": "5.8.1",
"dotenv": "^16.4.5",
"eslint": "8.7.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "8.8.0",
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-test-utils/src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const dockerRunCmds = {
'docker run --rm -d --name otel-mysql -p 33306:3306 -e MYSQL_ROOT_PASSWORD=rootpw -e MYSQL_DATABASE=test_db -e MYSQL_USER=otel -e MYSQL_PASSWORD=secret mysql:5.7 --log_output=TABLE --general_log=ON',
postgres:
'docker run --rm -d --name otel-postgres -p 54320:5432 -e POSTGRES_PASSWORD=postgres postgres:16-alpine',
redis: 'docker run --rm -d --name otel-redis -p 63790:6379 redis:alpine',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious, why this is no longer needed. Is not used anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it is no longer used. It was used by testUtils.startDocker('redis') calls, but those have been removed in the commits so far to this PR.

When all packages' testing is switched over to using this new test-services stuff, then startDocker, cleanUpDocker and all those dockerRunCmds entries can be removed from this file.

};

export function startDocker(db: keyof typeof dockerRunCmds) {
Expand Down
5 changes: 4 additions & 1 deletion plugins/node/instrumentation-mongoose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js-contrib",
"scripts": {
"docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
"test": "ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
"test-all-versions": "tav",
"test-services:start": "cd ../../.. && npm run test-services:start mongo",
"test-services:stop": "cd ../../.. && npm run test-services:stop mongo",
"test:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm test",
"test-all-versions:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm run test-all-versions",
"tdd": "npm run test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"lint": "eslint . --ext .ts",
Expand Down
7 changes: 7 additions & 0 deletions plugins/node/instrumentation-mongoose/test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ export const MONGO_HOST = process.env.MONGODB_HOST || 'localhost';
export const MONGO_PORT = Number(process.env.MONGODB_PORT || 27017);

export const MONGO_URI = `mongodb://${MONGO_HOST}/${MONGO_PORT}`;

export const shouldTest = process.env.RUN_MONGODB_TESTS != null;
if (!shouldTest) {
console.log(
'Skipping mongodb tests. Set RUN_MONGODB_TESTS=true to run them.'
);
}
17 changes: 14 additions & 3 deletions plugins/node/instrumentation-mongoose/test/mongoose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ const instrumentation = registerInstrumentationTesting(
import * as mongoose from 'mongoose';
import User, { IUser, loadUsers } from './user';
import { assertSpan, getStatement } from './asserts';
import { DB_NAME, MONGO_URI } from './config';
import { shouldTest, DB_NAME, MONGO_URI } from './config';

// Please run mongodb in the background: docker run -d -p 27017:27017 -v ~/data:/data/db mongo
describe('mongoose instrumentation', () => {
before(async () => {
if (!shouldTest) {
return;
}
try {
await mongoose.connect(MONGO_URI, {
useNewUrlParser: true,
Expand All @@ -63,7 +65,13 @@ describe('mongoose instrumentation', () => {
await mongoose.connection.close();
});

beforeEach(async () => {
beforeEach(async function mongooseBeforeEach() {
// Skipping all tests in beforeEach() is a workaround. Mocha does not work
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On pg tests there are some nested describes, and there there is only skip on the before and not on the before each, but is a little different:

    const skip = () => {
      // this.skip() workaround
      // https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901
      this.test!.parent!.pending = true;
      this.skip();
    };

    if (!shouldTest) {
      skip();
    }

maybe adding those extra lines help in your case too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll take a look.

This hunk that I added here was copying the same pattern from some of the instr-mongodb tests:

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v5-v6.test.ts
86:    // Skipping all tests in beforeEach() is a workaround. Mocha does not work

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4.test.ts
77:    // Skipping all tests in beforeEach() is a workaround. Mocha does not work

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts
76:    // Skipping all tests in beforeEach() is a workaround. Mocha does not work

plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v4-v5-v6.metrics.test.ts
106:    // Skipping all tests in beforeEach() is a workaround. Mocha does not work

// properly when skipping tests in before() on nested describe() calls.
// https://github.com/mochajs/mocha/issues/2819
if (!shouldTest) {
this.skip();
}
instrumentation.disable();
instrumentation.setConfig({
dbStatementSerializer: (_operation: string, payload) => {
Expand All @@ -78,6 +86,9 @@ describe('mongoose instrumentation', () => {
});

afterEach(async () => {
if (!shouldTest) {
return;
}
instrumentation.disable();
await User.collection.drop().catch();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"repository": "open-telemetry/opentelemetry-js-contrib",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'",
"test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test",
"test-services:start": "cd ../../.. && npm run test-services:start redis",
"test-services:stop": "cd ../../.. && npm run test-services:stop redis",
"test:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm test",
"test:debug": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'",
"test-all-versions": "tav",
"test-all-versions:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test-all-versions",
"test-all-versions:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm run test-all-versions",
"tdd": "npm run test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"lint": "eslint . --ext .ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ describe('ioredis', () => {
const provider = new NodeTracerProvider();
let ioredis: typeof ioredisTypes.default;
let instrumentation: IORedisInstrumentation;
const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL;
const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal;
const shouldTest = process.env.RUN_REDIS_TESTS;

let contextManager: AsyncHooksContextManager;
beforeEach(() => {
Expand All @@ -111,22 +110,12 @@ describe('ioredis', () => {
this.skip();
}

if (shouldTestLocal) {
testUtils.startDocker('redis');
}

provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
instrumentation = new IORedisInstrumentation();
instrumentation.setTracerProvider(provider);
ioredis = require('ioredis');
});

after(() => {
if (shouldTestLocal) {
testUtils.cleanUpDocker('redis');
}
});

it('should have correct module name', () => {
assert.strictEqual(
instrumentation.instrumentationName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js-contrib",
"scripts": {
"docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
"test": "npm run test-v5-v6",
"test-v3": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/mongodb-v3.test.ts'",
"test-v4": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v4.test.ts'",
"test-v5-v6": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/mongodb-v4-v5-v6.metrics.test.ts' 'test/**/mongodb-v5-v6.test.ts'",
"test-all-versions": "tav",
"test-services:start": "cd ../../.. && npm run test-services:start mongo",
"test-services:stop": "cd ../../.. && npm run test-services:stop mongo",
"test:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm test",
"test-all-versions:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm run test-all-versions",
"tdd": "npm run test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"lint": "eslint . --ext .ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"repository": "open-telemetry/opentelemetry-js-contrib",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/redis.test.ts'",
"test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/redis.test.ts'",
"test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test",
"test:docker:run": "docker run --rm -d --name otel-redis -p 63790:6379 redis:alpine",
"test:docker:stop": "docker stop otel-redis",
"test-services:start": "cd ../../.. && npm run test-services:start redis",
"test-services:stop": "cd ../../.. && npm run test-services:stop redis",
"test:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm test",
"test:debug": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/redis.test.ts'",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a .mocharc.cjs file for config options instead of specifying it in the CLI command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that then get used for normal test runs as well? My understanding of the point of the test:debug -- which existed before this change -- was to run with options other than a default npm run test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe mocha config files are like eslint config files where you can have multiple with custom names and pass them in wherever you need them. https://mochajs.org/#custom-locations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the diff for this part of this PR is not changing how ts-mocha is called:

-    "test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/redis.test.ts'",
+    "test:debug": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/redis.test.ts'",

I think changing to .mocharc.cjs is out of scope for this change and would distract from the test-services-related changes being made. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's fair. I was mostly pointing out because of the long npm scripts in general that you mentioned, but otherwise agree it doesn't need to happen here.

"test-all-versions": "tav",
"test-all-versions:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test-all-versions",
"test-all-versions:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm run test-all-versions",
"tdd": "npm run test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"lint": "eslint . --ext .ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ import { RedisInstrumentation } from '../src';
import type { MultiErrorReply } from '../src/internal-types';
import * as assert from 'assert';

import {
redisTestConfig,
redisTestUrl,
shouldTest,
shouldTestLocal,
} from './utils';
import * as testUtils from '@opentelemetry/contrib-test-utils';
import { redisTestConfig, redisTestUrl, shouldTest } from './utils';

const instrumentation = registerInstrumentationTesting(
new RedisInstrumentation()
Expand Down Expand Up @@ -61,16 +55,6 @@ describe('redis@^4.0.0', () => {
this.test!.parent!.pending = true;
this.skip();
}

if (shouldTestLocal) {
testUtils.startDocker('redis');
}
});

after(() => {
if (shouldTestLocal) {
testUtils.cleanUpDocker('redis');
}
});

let client: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ export const redisTestConfig = {

export const redisTestUrl = `redis://${redisTestConfig.host}:${redisTestConfig.port}`;

export const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL;
export const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal;
export const shouldTest = process.env.RUN_REDIS_TESTS;
10 changes: 5 additions & 5 deletions plugins/node/opentelemetry-instrumentation-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"repository": "open-telemetry/opentelemetry-js-contrib",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'",
"test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test",
"test:docker:run": "docker run --rm -d --name otel-redis -p 63790:6379 redis:alpine",
"test:docker:stop": "docker stop otel-redis",
"test-services:start": "cd ../../.. && npm run test-services:start redis",
"test-services:stop": "cd ../../.. && npm run test-services:stop redis",
"test:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm test",
"test:debug": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/redis.test.ts'",
"test-all-versions": "tav",
"test-all-versions:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test-all-versions",
"test-all-versions:with-test-services": "NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../../test/test-services.env npm run test-all-versions",
"tdd": "npm run test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"lint": "eslint . --ext .ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ describe('[email protected]', () => {
const provider = new NodeTracerProvider();
const tracer = provider.getTracer('external');
let redis: typeof redisTypes;
const shouldTestLocal = process.env.RUN_REDIS_TESTS_LOCAL;
const shouldTest = process.env.RUN_REDIS_TESTS || shouldTestLocal;
const shouldTest = process.env.RUN_REDIS_TESTS;

let contextManager: AsyncHooksContextManager;
beforeEach(() => {
Expand All @@ -93,22 +92,12 @@ describe('[email protected]', () => {
this.skip();
}

if (shouldTestLocal) {
testUtils.startDocker('redis');
}

redis = require('redis');
provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
instrumentation.setTracerProvider(provider);
instrumentation.enable();
});

after(() => {
if (shouldTestLocal) {
testUtils.cleanUpDocker('redis');
}
});

describe('#createClient()', () => {
it('should propagate the current span to event handlers', done => {
const span = tracer.startSpan('test span');
Expand Down
Loading