This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch parallel-eunit
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 1ce7058815b04de8071006dfa4f67d5569c2f9e9
Author: Jan Lehnardt <[email protected]>
AuthorDate: Fri Nov 28 12:15:46 2025 +0100

    wip: start parallelising eunit tests
---
 Makefile                    | 64 +++++++++++++++++++++++++++++++++------------
 src/couch/src/test_util.erl | 31 +++++++++++++++++++---
 2 files changed, 75 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile
index 6847037df..ce9a2222c 100644
--- a/Makefile
+++ b/Makefile
@@ -106,7 +106,7 @@ endif
 
 .PHONY: all
 # target: all - Build everything
-all: couch fauxton docs escriptize nouveau
+all: couch-core fauxton docs escriptize nouveau
 
 
 .PHONY: help
@@ -123,9 +123,9 @@ help:
 
################################################################################
 
 
-.PHONY: couch
-# target: couch - Build CouchDB core, use ERL_COMPILER_OPTIONS to provide 
custom compiler's options
-couch: config.erl
+.PHONY: couch-core
+# target: couch-core - Build CouchDB core, use ERL_COMPILER_OPTIONS to provide 
custom compiler's options
+couch-core: config.erl
        @COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) 
$(REBAR) compile $(COMPILE_OPTS)
 ifeq ($(with_spidermonkey), true)
        @cp src/couch/priv/couchjs bin/
@@ -146,7 +146,7 @@ fauxton: share/www
 
 .PHONY: escriptize
 # target: escriptize - Build CLI tools
-escriptize: couch
+escriptize: couch-core
        @$(REBAR) -r escriptize apps=weatherreport
        @cp src/weatherreport/weatherreport bin/weatherreport
 
@@ -168,23 +168,55 @@ check: all
        @$(MAKE) nouveau-test
 
 ifdef apps
-subdirs = $(apps)
+SUBDIRS = $(apps)
 else
-subdirs=$(shell ls src)
+SUBDIRS=$(shell ls src)
+# SUBDIRS=$(shell ls src | grep -v chttpd | grep -v couch_index)
 endif
 
-.PHONY: eunit
+
+# SUBDIRS = foo bar baz
+# 
+# .PHONY: subdirs $(SUBDIRS)
+# 
+# subdirs: $(SUBDIRS)
+# 
+# $(SUBDIRS):
+        # $(MAKE) -C $@
+# 
+# foo: baz
+
+.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
+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
+eunit: ${SUBDIRS}
+
+# $(SUBDIRS): export BUILDDIR = $(CURDIR)
+# $(SUBDIRS): export ERL_AFLAGS = -config $(CURDIR)/rel/files/eunit.config
+# $(SUBDIRS): export COUCHDB_QUERY_SERVER_JAVASCRIPT = $(CURDIR)/bin/couchjs 
$(CURDIR)/share/server/main.js
+# $(SUBDIRS): export COUCHDB_TEST_ADMIN_PARTY_OVERRIDE=1
+$(SUBDIRS):
+       @COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) 
$(REBAR) -r eunit $(EUNIT_OPTS) apps=$@ || exit 1
+
 
+# COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) 
$(MAKE) -C src/$@ eunit $(EUNIT_OPTS) apps=$@ REBAR=$(REBAR) || exit 1 # if we 
wanna move to sub-makefiles in all sub projects in src/ — 
 
 setup-eunit: export BUILDDIR = $(CURDIR)
 setup-eunit: export ERL_AFLAGS = -config $(CURDIR)/rel/files/eunit.config
@@ -199,7 +231,7 @@ just-eunit:
 .PHONY: soak-eunit
 soak-eunit: export BUILDDIR = $(CURDIR)
 soak-eunit: export ERL_AFLAGS = -config $(CURDIR)/rel/files/eunit.config
-soak-eunit: couch
+soak-eunit: couch-core
        @$(REBAR) setup_eunit 2> /dev/null
        while [ $$? -eq 0 ] ; do $(REBAR) -r eunit $(EUNIT_OPTS) ; done
 
@@ -356,7 +388,7 @@ weatherreport-test: devclean escriptize
 
 .PHONY: quickjs-test262
 # target: quickjs-javascript-tests - Run QuickJS JS conformance tests
-quickjs-test262: couch
+quickjs-test262: couch-core
        make -C src/couch_quickjs/quickjs test2-bootstrap
        make -C src/couch_quickjs/quickjs test2
 
@@ -578,7 +610,7 @@ endif
 nouveau-test: nouveau-test-gradle nouveau-test-elixir
 
 .PHONY: nouveau-test-gradle
-nouveau-test-gradle: couch nouveau
+nouveau-test-gradle: couch-core nouveau
 ifeq ($(with_nouveau), true)
        @cd nouveau && $(GRADLE) test --info --rerun
 endif
@@ -586,7 +618,7 @@ endif
 .PHONY: nouveau-test-elixir
 nouveau-test-elixir: export MIX_ENV=integration
 nouveau-test-elixir: elixir-init devclean
-nouveau-test-elixir: couch nouveau
+nouveau-test-elixir: couch-core nouveau
 ifeq ($(with_nouveau), true)
        @dev/run "$(TEST_OPTS)" -n 1 -q -a adm:pass --with-nouveau \
                --locald-config test/config/test-config.ini \
diff --git a/src/couch/src/test_util.erl b/src/couch/src/test_util.erl
index b8001840f..905ce74be 100644
--- a/src/couch/src/test_util.erl
+++ b/src/couch/src/test_util.erl
@@ -44,7 +44,7 @@
 -include("couch_db_int.hrl").
 -include("couch_bt_engine.hrl").
 
--record(test_context, {mocked = [], started = [], module}).
+-record(test_context, {mocked = [], started = [], module, dir}).
 
 -define(DEFAULT_APPS, [inets, ibrowse, ssl, config, couch_epi, couch_event, 
couch]).
 
@@ -82,16 +82,39 @@ start_couch(ExtraApps) ->
     start_couch(?CONFIG_CHAIN, ExtraApps).
 
 start_couch(IniFiles, ExtraApps) ->
+    % TODO Windows
+    RandomDir = filename:join(["/tmp/couchdb-tests", couch_uuids:random()]),
+    RandomEtcDir = filename:join([RandomDir, "etc"]),
+    RandomDataDir = ?b2l(filename:join([RandomDir, "data"])),
+
+    ok = filelib:ensure_path(RandomDir),
+    ok = filelib:ensure_path(RandomEtcDir),
+    ok = filelib:ensure_path(RandomDataDir),
+
+    RandomIniFiles = lists:map(fun(SourceFile) ->
+        TargetFileName = lists:last(filename:split(SourceFile)),
+        TargetFile = filename:join([RandomEtcDir, TargetFileName]),
+        {ok, _} = file:copy(SourceFile, TargetFile),
+        ?b2l(TargetFile)
+    end, IniFiles),
+    % ?debugFmt("~n~n IniFiles: ~p~n~n", [IniFiles]),
+    % ?debugFmt("~n~n RandomIniFiles: ~p~n~n", [RandomIniFiles]),
     load_applications_with_stats(),
-    ok = application:set_env(config, ini_files, IniFiles),
+    ok = application:set_env(config, ini_files, RandomIniFiles),
     Apps = start_applications(?DEFAULT_APPS ++ ExtraApps),
+
+    % ?debugFmt("~n~n RandomDataDir: ~p~n~n", [RandomDataDir]),
+
+    ok = config:set("couchdb", "database_dir", RandomDataDir, false),
+    ok = config:set("couchdb", "view_index_dir", RandomDataDir, false),
     ok = config:delete("compactions", "_default", false),
-    #test_context{started = Apps}.
+    #test_context{started = Apps, dir = RandomDir}.
 
 stop_couch() ->
     ok = stop_applications(?DEFAULT_APPS).
 
-stop_couch(#test_context{started = Apps}) ->
+stop_couch(#test_context{started = Apps, dir = DataDir }) ->
+    % file:del_dir_r(DataDir),
     stop_applications(Apps);
 stop_couch(_) ->
     stop_couch().

Reply via email to