Skip to content
Prev Previous commit
Next Next commit
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.
  • Loading branch information
janl committed Dec 4, 2025
commit 8604e57f29b4c118b080db7fa6d7f4a1f0fc4e4c
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,34 @@ check: all
@$(MAKE) nouveau-test

ifdef apps
subdirs = $(apps)
SUBDIRS = $(apps)
else
subdirs=$(shell ls src)
SUBDIRS=$(shell ls src)
endif

.PHONY: eunit
# Used for comparing behaviour against he new `eunit` target, delete once we
# are happy with the new `eunit`.
.PHONY: old-eunit
old-eunit: export BUILDDIR = $(CURDIR)
old-eunit: export ERL_AFLAGS = -config $(CURDIR)/rel/files/eunit.config
old-eunit: export COUCHDB_QUERY_SERVER_JAVASCRIPT = $(CURDIR)/bin/couchjs $(CURDIR)/share/server/main.js
old-eunit: export COUCHDB_TEST_ADMIN_PARTY_OVERRIDE=1
old-eunit:
@COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) setup_eunit 2> /dev/null
@for dir in $(SUBDIRS); do \
COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) -r eunit $(EUNIT_OPTS) apps=$$dir || exit 1; \
done

# target: eunit - Run EUnit tests, use EUNIT_OPTS to provide custom options
.PHONY: eunit $(SUBDIRS)
eunit: export BUILDDIR = $(CURDIR)
eunit: export ERL_AFLAGS = -config $(CURDIR)/rel/files/eunit.config
eunit: export COUCHDB_QUERY_SERVER_JAVASCRIPT = $(CURDIR)/bin/couchjs $(CURDIR)/share/server/main.js
eunit: export COUCHDB_TEST_ADMIN_PARTY_OVERRIDE=1
eunit: couch
@COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) setup_eunit 2> /dev/null
@for dir in $(subdirs); do \
COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) -r eunit $(EUNIT_OPTS) apps=$$dir || exit 1; \
done
eunit: ${SUBDIRS}

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

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