Skip to content

Commit 29e3fb9

Browse files
committed
feat: allow for parallel execution of make eunit sub-targets
When called with -jN for N>1, make will run `rebar -r eunit` for all src/* Erlang apps (without the default skipped ones) up to the limit of N times in parallel. This is best used with GNU Make, as it allows for controlling the output of each subtask to be grouped. BSD Make has no such feature and interleaves all parallel target’s output, making it hard to read. For example: gmake -j2 --output-sync=target will run two test suites in parallel and keep their respective outputs separated. It does this by buffering all output before a task is done that means for the first few tests, you don’t see output as you do with serial execution. On my machine I can run up to -j6 relatively stable, making use of all 14 cores. Beyond that, Spurious errors can occur. I’ll file those separately. -j2 shows an almost 2x speed improvement, as expected and things scale relatively linarly up until ~2.5 minutes of runtime, which seems to be a lower bound with all our various setup and wait bits. For comparison, -j1, that is serial execution takes about 10.5 minutes on this machine. Use with care in CI, but definitely use on your local dev machine.
1 parent 137df0e commit 29e3fb9

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

Makefile

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,34 @@ check: all
168168
@$(MAKE) nouveau-test
169169

170170
ifdef apps
171-
subdirs = $(apps)
171+
SUBDIRS = $(apps)
172172
else
173-
subdirs=$(shell ls src)
173+
SUBDIRS=$(shell ls src)
174174
endif
175175

176-
.PHONY: eunit
176+
# Used for comparing behaviour against he new `eunit` target, delete once we
177+
# are happy with the new `eunit`.
178+
.PHONY: old-eunit
179+
old-eunit: export BUILDDIR = $(CURDIR)
180+
old-eunit: export ERL_AFLAGS = -config $(CURDIR)/rel/files/eunit.config
181+
old-eunit: export COUCHDB_QUERY_SERVER_JAVASCRIPT = $(CURDIR)/bin/couchjs $(CURDIR)/share/server/main.js
182+
old-eunit: export COUCHDB_TEST_ADMIN_PARTY_OVERRIDE=1
183+
old-eunit:
184+
@COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) setup_eunit 2> /dev/null
185+
@for dir in $(SUBDIRS); do \
186+
COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) -r eunit $(EUNIT_OPTS) apps=$$dir || exit 1; \
187+
done
188+
177189
# target: eunit - Run EUnit tests, use EUNIT_OPTS to provide custom options
190+
.PHONY: eunit $(SUBDIRS)
178191
eunit: export BUILDDIR = $(CURDIR)
179192
eunit: export ERL_AFLAGS = -config $(CURDIR)/rel/files/eunit.config
180193
eunit: export COUCHDB_QUERY_SERVER_JAVASCRIPT = $(CURDIR)/bin/couchjs $(CURDIR)/share/server/main.js
181194
eunit: export COUCHDB_TEST_ADMIN_PARTY_OVERRIDE=1
182-
eunit: couch
183-
@COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) setup_eunit 2> /dev/null
184-
@for dir in $(subdirs); do \
185-
COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) -r eunit $(EUNIT_OPTS) apps=$$dir || exit 1; \
186-
done
195+
eunit: ${SUBDIRS}
187196

197+
$(SUBDIRS): setup-eunit
198+
@COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) -r eunit $(EUNIT_OPTS) apps=$@ #|| exit 1
188199

189200
setup-eunit: export BUILDDIR = $(CURDIR)
190201
setup-eunit: export ERL_AFLAGS = -config $(CURDIR)/rel/files/eunit.config

0 commit comments

Comments
 (0)