Skip to content

Commit fd3a8b7

Browse files
committed
test(instrumentation): parallelize and clean up tests
1 parent b5e9fa6 commit fd3a8b7

12 files changed

Lines changed: 45 additions & 50 deletions

File tree

circle.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ test:
1818
override:
1919
- ./scripts/run-ci.sh ./scripts/prepare.sh
2020
- ./scripts/run-ci.sh ./scripts/lint.sh
21-
- ./scripts/run-ci.sh ./scripts/node-matrix.sh ./scripts/prepare.sh ./scripts/test-unit.sh ./scripts/test-cover.sh ./scripts/test-e2e.sh:
21+
- ./scripts/run-ci.sh ./scripts/node-matrix.sh ./scripts/prepare.sh ./scripts/test-unit.sh ./scripts/test-cover.sh ./scripts/test-e2e.sh && ./scripts/run-ci.sh ./scripts/test-instrumentations.sh:
2222
parallel: true
23-
- ./scripts/run-ci.sh ./scripts/prepare.sh
24-
- ./scripts/run-ci.sh ./scripts/test-instrumentations.sh
2523

2624
deployment:
2725
release:

scripts/test-instrumentations.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ if [[ -z $INSTR_TARGET_VERSIONS ]]; then
99
fi
1010

1111
cd ./test/instrumentations
12-
make test TARGET_VERSIONS=$INSTR_TARGET_VERSIONS
12+
make test TARGET_VERSIONS=$INSTR_TARGET_VERSIONS \
13+
NODE_INDEX=$NODE_INDEX NODE_TOTAL=$NODE_TOTAL

test/instrumentations/Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ cur_path := $(abspath $(lastword $(MAKEFILE_LIST)))
44
cur_dir := $(dir $(cur_path))
55
cur_base := $(notdir $(cur_path))
66

7+
export PATH := $(shell npm bin):$(PATH)
8+
79
# Use this variable for invoking the test runner
810
export MOCHA := $(shell npm bin)/mocha
911

@@ -15,21 +17,32 @@ export MOCHA := $(shell npm bin)/mocha
1517
# one: most important version, stable version for smoke test
1618
#
1719
# Default is all, but it can be overriden from the command line
18-
TARGET_VERSIONS?=all
20+
TARGET_VERSIONS ?= all
1921
configure_targets = $(if $(filter one,$(TARGET_VERSIONS)),$(1),$(if $(filter some,$(TARGET_VERSIONS)),$(2),)$(if $(filter all,$(TARGET_VERSIONS)),$(3),))
2022

2123
# Every library instrumentation should have a subrecipe in its directory
2224
# containing the target test_suite_<LIBRARY_NAME>
2325
# and should append <LIBRARY_NAME> to the variable `targets`
24-
include $(cur_dir)/*/*.mk
26+
ifndef TARGET_LIBRARIES
27+
include $(cur_dir)/*/*.mk
28+
else
29+
include $(patsubst %, $(cur_dir)/%/*.mk, $(TARGET_LIBRARIES))
30+
endif
31+
32+
# Used for running tests in parallel if possible which will speed up the job on
33+
# CircleCI.
34+
NODE_INDEX ?= 0
35+
NODE_TOTAL ?= 1
2536

26-
# We have a common package json for every test suite, because it is much more
27-
# fast this way. Of course you could install other dependencies in the test
28-
# suites. This is actually needed for versioning.
37+
# We have a common package json for every test suite, because it is faster
38+
# this way. Of course you could install other dependencies in the test suites.
39+
# This is actually needed for versioning.
2940
before :
41+
@node --version
42+
@npm --version
3043
npm i
3144

32-
test : $(targets:%=test_suite_%)
45+
test : $(shell $(cur_dir)/distribute-tasks.py $(NODE_INDEX) $(NODE_TOTAL) $(targets:%=test_suite_%))
3346

3447
# On best practices for writing a test suite for an instrumentation, please
3548
# see mysql/mysql.mk

test/instrumentations/amqplib/amqplib.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ before_$(target) : before
3131
@echo '*---------------*'
3232
@echo '| amqplib |'
3333
@echo '*---------------*'
34-
npm i amqplib
34+
@npm i amqplib
3535
AMQP_URL=$(amqp_url) $(addprefix $(cur_dir), verify.js)
3636

3737
# this should run after `before` for each of the version targets
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python2
2+
import sys
3+
import math
4+
5+
node_index = int(sys.argv[1])
6+
node_total = int(sys.argv[2])
7+
tasks = sys.argv[3:]
8+
task_total = len(tasks)
9+
10+
config = [
11+
tasks[i * node_total + node_index]
12+
for i in range(0, int(math.ceil(task_total / node_total)) + 1)
13+
if (i * node_total + node_index) < task_total
14+
]
15+
print ' '.join(config)

test/instrumentations/index.spec.cls.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/instrumentations/mongodb/mongodb.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ before_$(target) : before
3030
@echo '*---------------*'
3131
@echo '| mongodb |'
3232
@echo '*---------------*'
33-
npm i mongodb
33+
@npm i mongodb
3434
$(addprefix $(cur_dir), dbVerify.js) $(db_url)
3535

3636
# this should run after `before` for each of the version targets

test/instrumentations/mysql/mysql.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ before_$(target) : before
5959
@echo '*---------------*'
6060
@echo '| mysql |'
6161
@echo '*---------------*'
62-
npm i mysql
62+
@npm i mysql
6363
# this script throws an error if it can't access the db
6464
MYSQL_HOST=$(db_host) $(addprefix $(cur_dir), dbVerify.js)
6565

test/instrumentations/package.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,10 @@
33
"name": "@risingstack/trace-tests-instrumentation",
44
"devDependencies": {
55
"@risingstack/trace": "../..",
6-
"body-parser": "1.15.2",
7-
"bookshelf": "0.10.2",
8-
"cassandra-driver": "3.1.6",
96
"chai": "3.5.0",
107
"freshy": "^1.0.2",
11-
"ioredis": "2.4.2",
12-
"knex": "0.12.6",
13-
"koa": "1.2.4",
14-
"lodash.defaultsdeep": "^4.5.1",
15-
"memcached": "2.2.2",
168
"mocha": "3.2.0",
17-
"mongoose": "4.7.2",
18-
"redis": "2.6.3",
199
"sinon": "1.17.6",
20-
"sinon-chai": "2.8.0",
21-
"superagent": "3.2.1",
22-
"supertest": "2.0.1"
10+
"sinon-chai": "2.8.0"
2311
}
2412
}

test/instrumentations/pg/pg.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ before_$(target) : before
3131
@echo '*---------------*'
3232
@echo '| pg |'
3333
@echo '*---------------*'
34-
npm i pg pg-native
35-
npm rebuild
34+
@npm i pg pg-native
3635
DB_URL=$(db_url) $(addprefix $(cur_dir), dbVerify.js)
3736

3837
# this should run after `before` for each of the version targets

0 commit comments

Comments
 (0)