mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 01:53:41 +08:00
Run tests on temp Postgres instance
Tests are now run on a temporary Postgres instance, which is launched by the `pg_regress` test runner. This allows running tests without having an existing running instance with a matching configuration and also obviates the need for preloading the TimescaleDB extension. As a result, tests are simpler to setup and run, and are more reliable and consistent.
This commit is contained in:
parent
997029a86d
commit
d17976538b
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@
|
||||
/timescaledb.so
|
||||
*.bak
|
||||
typedef.list
|
||||
/test/testcluster
|
||||
|
25
Makefile
25
Makefile
@ -46,22 +46,35 @@ DEPS = $(SRCS:.c=.d)
|
||||
MKFILE_PATH := $(abspath $(MAKEFILE_LIST))
|
||||
CURRENT_DIR = $(dir $(MKFILE_PATH))
|
||||
|
||||
TEST_PGPORT ?= 5432
|
||||
TEST_PGPORT ?= 15432
|
||||
TEST_PGHOST ?= localhost
|
||||
TEST_PGUSER ?= postgres
|
||||
TEST_DIR = test
|
||||
TEST_CLUSTER ?= $(TEST_DIR)/testcluster
|
||||
TEST_INSTANCE_OPTS ?= \
|
||||
--create-role=$(TEST_PGUSER) \
|
||||
--temp-instance=$(TEST_CLUSTER) \
|
||||
--temp-config=$(TEST_DIR)/postgresql.conf
|
||||
|
||||
EXTRA_REGRESS_OPTS ?=
|
||||
|
||||
export TEST_PGUSER
|
||||
|
||||
TESTS = $(sort $(wildcard test/sql/*.sql))
|
||||
USE_MODULE_DB=true
|
||||
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
|
||||
REGRESS_OPTS = \
|
||||
--inputdir=test \
|
||||
--outputdir=test \
|
||||
--launcher=test/runner.sh \
|
||||
$(TEST_INSTANCE_OPTS) \
|
||||
--inputdir=$(TEST_DIR) \
|
||||
--outputdir=$(TEST_DIR) \
|
||||
--launcher=$(TEST_DIR)/runner.sh \
|
||||
--host=$(TEST_PGHOST) \
|
||||
--port=$(TEST_PGPORT) \
|
||||
--user=$(TEST_PGUSER) \
|
||||
--load-language=plpgsql \
|
||||
--load-extension=postgres_fdw \
|
||||
--load-extension=$(EXTENSION)
|
||||
--load-extension=$(EXTENSION) \
|
||||
$(EXTRA_REGRESS_OPTS)
|
||||
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
|
||||
@ -69,7 +82,7 @@ EXTRA_CLEAN = $(EXT_SQL_FILE) $(DEPS)
|
||||
|
||||
include $(PGXS)
|
||||
override CFLAGS += -DINCLUDE_PACKAGE_SUPPORT=0 -MMD
|
||||
override pg_regress_clean_files = test/results/ test/regression.diffs test/regression.out tmp_check/ log/
|
||||
override pg_regress_clean_files = test/results/ test/regression.diffs test/regression.out tmp_check/ log/ $(TEST_CLUSTER)
|
||||
-include $(DEPS)
|
||||
|
||||
all: $(EXT_SQL_FILE)
|
||||
|
@ -5,6 +5,7 @@ MAKE = make
|
||||
PGPORT = 5432
|
||||
TEST_PGPORT = 6543
|
||||
TEST_TABLESPACE_PATH = /tmp/tspace1
|
||||
TEST_INSTANCE_OPTS = # clear this setting when running against existing Docker instance
|
||||
|
||||
build-image: Dockerfile
|
||||
@docker build . -t $(IMAGE_NAME)
|
||||
|
2
test/postgresql.conf
Normal file
2
test/postgresql.conf
Normal file
@ -0,0 +1,2 @@
|
||||
timescaledb.allow_install_without_preload = 'on'
|
||||
shared_preload_libraries = 'timescaledb'
|
@ -4,13 +4,20 @@ set -u
|
||||
set -e
|
||||
|
||||
PG_REGRESS_PSQL=$1
|
||||
shift
|
||||
PSQL=${PSQL:-$PG_REGRESS_PSQL}
|
||||
TEST_PGUSER=${TEST_PGUSER:-postgres}
|
||||
TEST_TABLESPACE_PATH=${TEST_TABLESPACE_PATH:-/tmp/tspace1}
|
||||
|
||||
shift
|
||||
|
||||
# Setup directories required by tests
|
||||
cd test/sql
|
||||
PG_PROC_USER=$(ps u | awk '/postgres/ { print $1; exit }')
|
||||
mkdir -p ${TEST_TABLESPACE_PATH}
|
||||
mkdir -p dump
|
||||
|
||||
exec ${PSQL} -v ON_ERROR_STOP=1 -v VERBOSITY=terse -v ECHO=all -v TEST_TABLESPACE_PATH=\'${TEST_TABLESPACE_PATH}\' $@
|
||||
# Hack to grant TEST_PGUSER superuser status so that we can
|
||||
# consistently run tests using the same user rather than the
|
||||
# current/local user
|
||||
${PSQL} $@ -v ECHO=none -c "ALTER USER ${TEST_PGUSER} WITH SUPERUSER;"
|
||||
|
||||
exec ${PSQL} -U ${TEST_PGUSER} -v ON_ERROR_STOP=1 -v VERBOSITY=terse -v ECHO=all -v TEST_TABLESPACE_PATH=\'${TEST_TABLESPACE_PATH}\' $@
|
||||
|
Loading…
x
Reference in New Issue
Block a user