1
0
mirror of https://github.com/timescale/timescaledb.git synced 2025-05-16 10:33:27 +08:00

Support test groups with different configurations

To support tests with different configuration options, we split the
tests into *test configurations*. Each test configuration NAME will have

- A configuration template file `NAME.conf.in` that is used to run the
  suite of tests.
- A variable `TEST_FILES_<NAME>` listing the test files available for
  that test suite.
- A variable `SOLO_TESTS_<NAME>` that lists the tests that need to be
  run as solo tests.

The code to generate test schedules is then factored out into a
separate file and used for each configuration.
This commit is contained in:
Mats Kindahl 2022-01-28 13:30:32 +01:00 committed by Mats Kindahl
parent 9248de2f2a
commit 05dd4787d1
9 changed files with 220 additions and 101 deletions

@ -16,14 +16,22 @@ endfunction()
#
# Generate a script file and install it into the script directory.
#
# VERSION <version> Version to use for shared libraryx.
# VERSION <version>
#
# SCRIPT <file> File name for script file.
# Version to use for shared libraryx.
#
# OUTPUT_DIRECTORY <dir> Directory for where script file should be written.
# Defaults to CMAKE_CURRENT_BINARY_DIR.
# SCRIPT <file>
#
# FILES <file> ... List of files to include, in order, in the script file.
# File name for script file.
#
# OUTPUT_DIRECTORY <dir>
#
# Directory for where script file should be written. Defaults to
# CMAKE_CURRENT_BINARY_DIR.
#
# FILES <file> ...
#
# List of files to include, in order, in the script file.
function(generate_script)
set(options)
set(oneValueArgs VERSION SCRIPT OUTPUT_DIRECTORY)
@ -63,14 +71,13 @@ endfunction()
# generate_downgrade_script(<options>)
#
# Create a downgrade script from a source version to a target
# version. To figure out what files are necessary, the
# ScriptFiles.cmake manifest is read from the target version. If that
# file does not exist in the target version, the manifest in the
# current version is used, but it is assumed that files are only
# added. This situation only occur in the first version where we start
# to generate downgrade scripts and in this case files were only
# added, so we can safely ignore them.
# Create a downgrade script from a source version to a target version. To figure
# out what files are necessary, the ScriptFiles.cmake manifest is read from the
# target version. If that file does not exist in the target version, the
# manifest in the current version is used, but it is assumed that files are only
# added. This situation only occur in the first version where we start to
# generate downgrade scripts and in this case files were only added, so we can
# safely ignore them.
#
# SOURCE_VERSION <version>
#
@ -92,9 +99,8 @@ endfunction()
#
# Files to include, in order, when generating the downgrade script.
#
# The downgrade script is generated by creating a new file of the
# format "timescaledb--<current>--<version>.sql" consisting of the
# sequence of files:
# The downgrade script is generated by creating a new file of the format
# "timescaledb--<current>--<version>.sql" consisting of the sequence of files:
#
# 1. Generated prolog from the target version
# 2. Generated downgrade files from the source version
@ -106,8 +112,9 @@ endfunction()
# LOADER_PATHNAME: Pathname to loader shared library. This is the same as in the
# update.
#
# MODULE_PATHNAME: Pathname to timescale extension of the version being dowgraded
# to. This can be used to load "old" functions from the correct library.
# MODULE_PATHNAME: Pathname to timescale extension of the version being
# dowgraded to. This can be used to load "old" functions from the correct
# library.
function(generate_downgrade_script)
set(options)
set(oneValueArgs SOURCE_VERSION TARGET_VERSION OUTPUT_DIRECTORY
@ -129,14 +136,13 @@ function(generate_downgrade_script)
endif()
endforeach()
# Fetch manifest with list of files for the prolog and epilog from
# the target version, if we are in a version that supports
# downgrades. Otherwise, take the one in the current version.
# Fetch manifest with list of files for the prolog and epilog from the target
# version, if we are in a version that supports downgrades. Otherwise, take
# the one in the current version.
#
# We have a specific exception where we allow a missing manifest for
# the first version that supports downgrades and assume that the
# files to include are the same in the target version as the current
# one.
# We have a specific exception where we allow a missing manifest for the first
# version that supports downgrades and assume that the files to include are
# the same in the target version as the current one.
if(_downgrade_TARGET_VERSION VERSION_GREATER 2.3)
git_versioned_get(VERSION ${_downgrade_TARGET_VERSION} FILES
${CMAKE_SOURCE_DIR}/cmake/ScriptFiles.cmake)

@ -0,0 +1,55 @@
# generate_test_schedul(<output file> ...)
#
# A test schedule is generated for the files in TEST_FILES. The test schedule
# groups the tests into groups of size GROUP_SIZE, with the exceptions of any
# tests mentioned in the list SOLO, which will be in their own test group.
#
# TEST_FILES <file> ...
#
# Test files to generate a test schedule for.
#
# SOLO <test> ...
#
# Names of tests that should be run as solo tests. Note that these are test
# names, not file names.
#
# GROUP_SIZE
#
# Size of each group in the test schedule.
function(generate_test_schedule OUTPUT_FILE)
set(options)
set(oneValueArgs GROUP_SIZE)
set(multiValueArgs TEST_FILES SOLO)
cmake_parse_arguments(_generate "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
list(SORT _generate_TEST_FILES)
file(REMOVE ${OUTPUT_FILE})
# We put the solo tests in the test file first. Note that we do not generate
# groups for solo tests that are not in the list of test files.
foreach(_solo ${_generate_SOLO})
if("${_solo}.sql" IN_LIST _generate_TEST_FILES)
file(APPEND ${OUTPUT_FILE} "test: ${_solo}\n")
endif()
endforeach()
# Generate groups of tests
set(_members 0)
foreach(_file ${_generate_TEST_FILES})
string(REGEX REPLACE "(.+)\.sql" "\\1" _test ${_file})
if(NOT (_test IN_LIST _generate_SOLO))
if(_members EQUAL 0)
file(APPEND ${OUTPUT_FILE} "test: ")
endif()
file(APPEND ${OUTPUT_FILE} "${_test} ")
if(_members LESS _generate_GROUP_SIZE)
math(EXPR _members "${_members} + 1")
else()
set(_members 0)
file(APPEND ${OUTPUT_FILE} "\n")
endif()
endif()
endforeach()
file(APPEND ${OUTPUT_FILE} "\n")
endfunction()

@ -19,10 +19,11 @@ if(PG_REGRESS)
regresscheck
COMMAND
${CMAKE_COMMAND} -E env ${PG_REGRESS_ENV}
TEST_PGPORT=${TEST_PGPORT_TEMP_INSTANCE}
TEST_PGPORT=${TEST_PGPORT_TEMP_INSTANCE} TEST_SCHEDULE=${TEST_SCHEDULE}
${CMAKE_CURRENT_SOURCE_DIR}/pg_regress.sh ${PG_REGRESS_OPTS_BASE}
${PG_REGRESS_OPTS_EXTRA} ${PG_REGRESS_OPTS_INOUT}
${PG_REGRESS_OPTS_TEMP_INSTANCE}
--temp-config=${TEST_OUTPUT_DIR}/postgresql.conf
USES_TERMINAL)
add_custom_target(
@ -53,6 +54,7 @@ if(PG_ISOLATION_REGRESS)
${CMAKE_CURRENT_SOURCE_DIR}/pg_regress.sh ${PG_REGRESS_OPTS_BASE}
${PG_ISOLATION_REGRESS_OPTS_EXTRA} ${PG_ISOLATION_REGRESS_OPTS_INOUT}
${PG_REGRESS_OPTS_TEMP_INSTANCE}
--temp-config=${TEST_OUTPUT_DIR}/postgresql.conf
USES_TERMINAL)
add_custom_target(

21
test/max_bgw_8.conf.in Normal file

@ -0,0 +1,21 @@
# NOTE: any changes here require changes to two other places
# 1) tsl/test/postgresql.conf requires that it's prefix be the same as this file.
# 2) appveyor.yml needs to be updated with the same options
shared_preload_libraries=timescaledb
max_worker_processes=16
autovacuum=false
random_page_cost=1.0
timescaledb.license='apache'
@TELEMETRY_DEFAULT_SETTING@
timescaledb.last_tuned='1971-02-03 04:05:06.789012 -0300'
timescaledb.last_tuned_version='0.0.1'
timescaledb_telemetry.cloud='ci'
log_line_prefix='%u [%p] %d '
# PG12 changed the default rounding behavior of floating point
# numbers. Setting extra_float_digits=0 retains the old behavior which
# is needed to make our tests work for multiple PostgreSQL versions.
extra_float_digits=0
timescaledb.passfile='@TEST_PASSFILE@'
hba_file='@TEST_PG_HBA_FILE@'
timescaledb.max_background_workers = 8

@ -1,3 +1,5 @@
include(GenerateTestSchedule)
set(TEST_FILES
alter.sql
alternate_users.sql
@ -126,34 +128,20 @@ foreach(TEMPLATE_FILE ${TEST_TEMPLATES})
list(APPEND TEST_FILES ${TEST_FILE})
endforeach(TEMPLATE_FILE)
list(SORT TEST_FILES)
file(REMOVE ${TEST_SCHEDULE})
if(NOT TEST_GROUP_SIZE)
set(PARALLEL_GROUP_SIZE 20)
else()
set(PARALLEL_GROUP_SIZE ${TEST_GROUP_SIZE})
endif()
# append solo tests to schedule first
foreach(SOLO_TEST_NAME ${SOLO_TESTS})
string(REGEX REPLACE "(.+)" "\\1.sql" TEST_FILE ${SOLO_TEST_NAME})
if(TEST_FILE IN_LIST TEST_FILES)
file(APPEND ${TEST_SCHEDULE} "test: ${SOLO_TEST_NAME}\n")
endif()
endforeach(SOLO_TEST_NAME)
set(GROUP_MEMBERS 0)
foreach(TEST_FILE ${TEST_FILES})
string(REGEX REPLACE "(.+)\.sql" "\\1" TESTS_TO_RUN ${TEST_FILE})
if(NOT (TESTS_TO_RUN IN_LIST SOLO_TESTS))
if(GROUP_MEMBERS EQUAL 0)
file(APPEND ${TEST_SCHEDULE} "\ntest: ")
endif()
file(APPEND ${TEST_SCHEDULE} "${TESTS_TO_RUN} ")
math(EXPR GROUP_MEMBERS "(${GROUP_MEMBERS}+1)%${PARALLEL_GROUP_SIZE}")
endif()
endforeach(TEST_FILE)
file(APPEND ${TEST_SCHEDULE} "\n")
# Generate a test schedule for each configuration.
generate_test_schedule(
${TEST_SCHEDULE}
TEST_FILES
${TEST_FILES}
SOLO
${SOLO_TESTS}
GROUP_SIZE
${PARALLEL_GROUP_SIZE})
add_subdirectory(loader)

@ -43,6 +43,7 @@ configure_file(${PRIMARY_TEST_DIR}/pg_hba.conf.in pg_hba.conf)
set(TEST_PG_HBA_FILE ${TEST_OUTPUT_DIR}/pg_hba.conf)
configure_file(postgresql.conf.in postgresql.conf)
configure_file(max_bgw_8.conf.in max_bgw_8.conf)
# pgpass file requires chmod 0600
configure_file(${PRIMARY_TEST_DIR}/pgpass.conf.in

@ -8,14 +8,27 @@ set(_install_checks)
# No checks for REGRESS_CHECKS needed here since all the checks are done in the
# parent CMakeLists.txt.
if(PG_REGRESS)
# This custom target executes one command for each test configuration. It
# might be possible to automatically generate this custom target, but for now
# the configurations are hard-coded.
add_custom_target(
regresscheck-t
COMMAND
${CMAKE_COMMAND} -E env ${PG_REGRESS_ENV}
EXE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
TEST_SCHEDULE=${TEST_SCHEDULE}_postgresql
TEST_PGPORT=${TEST_PGPORT_TEMP_INSTANCE} ${PRIMARY_TEST_DIR}/pg_regress.sh
${PG_REGRESS_OPTS_BASE} ${PG_REGRESS_OPTS_EXTRA} ${PG_REGRESS_OPTS_INOUT}
${PG_REGRESS_OPTS_TEMP_INSTANCE}
--temp-config=${TEST_OUTPUT_DIR}/postgresql.conf
COMMAND
${CMAKE_COMMAND} -E env ${PG_REGRESS_ENV}
EXE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
TEST_SCHEDULE=${TEST_SCHEDULE}_max_bgw_8
TEST_PGPORT=${TEST_PGPORT_TEMP_INSTANCE} ${PRIMARY_TEST_DIR}/pg_regress.sh
${PG_REGRESS_OPTS_BASE} ${PG_REGRESS_OPTS_EXTRA} ${PG_REGRESS_OPTS_INOUT}
${PG_REGRESS_OPTS_TEMP_INSTANCE}
--temp-config=${TEST_OUTPUT_DIR}/max_bgw_8.conf
USES_TERMINAL)
add_custom_target(
@ -40,6 +53,7 @@ if(PG_REGRESS)
TEST_PGPORT=${TEST_PGPORT_TEMP_INSTANCE} ${PRIMARY_TEST_DIR}/pg_regress.sh
${PG_REGRESS_OPTS_BASE} ${PG_REGRESS_SHARED_OPTS_EXTRA}
${PG_REGRESS_SHARED_OPTS_INOUT} ${PG_REGRESS_OPTS_TEMP_INSTANCE}
--temp-config=${TEST_OUTPUT_DIR}/postgresql.conf
USES_TERMINAL)
add_custom_target(
@ -88,6 +102,7 @@ if(PG_ISOLATION_REGRESS)
TEST_PGPORT=${TEST_PGPORT_TEMP_INSTANCE} ${PRIMARY_TEST_DIR}/pg_regress.sh
${PG_REGRESS_OPTS_BASE} ${PG_ISOLATION_REGRESS_OPTS_EXTRA}
${PG_ISOLATION_REGRESS_OPTS_INOUT} ${PG_REGRESS_OPTS_TEMP_INSTANCE}
--temp-config=${TEST_OUTPUT_DIR}/postgresql.conf
USES_TERMINAL)
add_custom_target(

@ -0,0 +1,30 @@
# This section has to be equivalent to test/postgresql.conf
shared_preload_libraries=timescaledb
max_worker_processes=16
autovacuum=false
random_page_cost=1.0
@TELEMETRY_DEFAULT_SETTING@
timescaledb.last_tuned='1971-02-03 04:05:06.789012 -0300'
timescaledb.last_tuned_version='0.0.1'
timescaledb_telemetry.cloud='ci'
log_line_prefix='%u [%p] '
timescaledb.max_background_workers = 8
# This section adds additional options required by TSL
# Note any changes here require updates to appveyor.yml
timescaledb.license='timescale'
log_line_prefix='%u [%p] %d '
# PG12 changed the default rounding behavior of floating point
# numbers. Setting extra_float_digits=0 retains the old behavior which
# is needed to make our tests work for multiple PostgreSQL versions.
extra_float_digits=0
max_connections=200
max_prepared_transactions=100 #set same as max_connections
hba_file='@TEST_PG_HBA_FILE@'
ssl=on
ssl_ca_file='@TEST_OUTPUT_DIR@/ts_root.crt'
ssl_cert_file='@TEST_OUTPUT_DIR@/ts_data_node.crt'
ssl_key_file='@TEST_OUTPUT_DIR@/ts_data_node.key'
timescaledb.ssl_dir='@TEST_OUTPUT_DIR@/timescaledb/certs'
timescaledb.passfile='@TEST_PASSFILE@'
wal_level='logical'

@ -1,4 +1,13 @@
set(TEST_FILES
include(GenerateTestSchedule)
# These are the configurations. There has to be a file whatever.conf.in for each
# configuration name in this list and the corresponding variables use the
# configuration name as a suffix.
set(TEST_CONFIGURATIONS postgresql max_bgw_8)
# These are the files for the 'postgresql' configuration. This is the default,
# so unless you have a good reason, add new test files here.
set(TEST_FILES_postgresql
bgw_custom.sql
bgw_policy.sql
compression_bgw.sql
@ -17,8 +26,10 @@ set(TEST_FILES
reorder.sql
skip_scan.sql)
set(TEST_FILES_DEBUG
bgw_db_scheduler.sql
if(CMAKE_BUILD_TYPE MATCHES Debug)
list(
APPEND
TEST_FILES_postgresql
bgw_reorder_drop_chunks.sql
compress_bgw_reorder_drop_chunks.sql
chunk_api.sql
@ -74,6 +85,34 @@ set(TEST_FILES_DEBUG
tsl_tables.sql
license.sql)
endif(CMAKE_BUILD_TYPE MATCHES Debug)
set(SOLO_TESTS_postgresql
bgw_reorder_drop_chunks
compress_bgw_reorder_drop_chunks
compression_ddl
cagg_bgw
cagg_ddl
cagg_ddl_dist_ht
cagg_dump
data_fetcher
dist_util
move
remote_connection_cache
remote_copy
remote_txn
remote_txn_resolve
reorder
telemetry_distributed)
# Test files for the max_bgw_8 configuration that configures TimescaleDB with a
# max of 8 TimescaleDB background workers.
set(TEST_FILES_max_bgw_8)
set(SOLO_TESTS_max_bgw_8 bgw_db_scheduler)
if(CMAKE_BUILD_TYPE MATCHES Debug)
list(APPEND TEST_FILES_max_bgw_8 bgw_db_scheduler.sql)
endif()
set(TEST_TEMPLATES
compression_insert.sql.in cagg_union_view.sql.in plan_skip_scan.sql.in
transparent_decompression.sql.in
@ -94,28 +133,6 @@ if(EXISTS ${PG_CONFIG_H})
endif()
endif()
# the following tests will run by itself before the parallel tests because they
# fail or are flaky when run in parallel dist_views.sql sets some global
# information, so do not run it in parallel
set(SOLO_TESTS
bgw_db_scheduler
bgw_reorder_drop_chunks
compress_bgw_reorder_drop_chunks
compression_ddl
cagg_bgw
cagg_ddl
cagg_ddl_dist_ht
cagg_dump
data_fetcher
dist_util
move
remote_connection_cache
remote_copy
remote_txn
remote_txn_resolve
reorder
telemetry_distributed)
# Regression tests that vary with PostgreSQL version. Generated test files are
# put in the original source directory since all tests must be in the same
# directory. These files are updated when the template is edited, but not when
@ -131,36 +148,20 @@ foreach(TEMPLATE_FILE ${TEST_TEMPLATES})
list(APPEND TEST_FILES ${TEST_FILE})
endforeach(TEMPLATE_FILE)
if(CMAKE_BUILD_TYPE MATCHES Debug)
list(APPEND TEST_FILES ${TEST_FILES_DEBUG})
endif(CMAKE_BUILD_TYPE MATCHES Debug)
list(SORT TEST_FILES)
file(REMOVE ${TEST_SCHEDULE})
if(NOT TEST_GROUP_SIZE)
set(PARALLEL_GROUP_SIZE 10)
else()
set(PARALLEL_GROUP_SIZE ${TEST_GROUP_SIZE})
endif()
# append solo tests to schedule first
foreach(SOLO_TEST_NAME ${SOLO_TESTS})
string(REGEX REPLACE "(.+)" "\\1.sql" TEST_FILE ${SOLO_TEST_NAME})
if(TEST_FILE IN_LIST TEST_FILES)
file(APPEND ${TEST_SCHEDULE} "test: ${SOLO_TEST_NAME}\n")
endif()
endforeach(SOLO_TEST_NAME)
set(GROUP_MEMBERS 0)
foreach(TEST_FILE ${TEST_FILES})
string(REGEX REPLACE "(.+)\.sql" "\\1" TESTS_TO_RUN ${TEST_FILE})
if(NOT (TESTS_TO_RUN IN_LIST SOLO_TESTS))
if(GROUP_MEMBERS EQUAL 0)
file(APPEND ${TEST_SCHEDULE} "\ntest: ")
endif()
file(APPEND ${TEST_SCHEDULE} "${TESTS_TO_RUN} ")
math(EXPR GROUP_MEMBERS "(${GROUP_MEMBERS}+1)%${PARALLEL_GROUP_SIZE}")
endif()
endforeach(TEST_FILE)
file(APPEND ${TEST_SCHEDULE} "\n")
# Generate a test schedule for each configuration.
foreach(_conf ${TEST_CONFIGURATIONS})
generate_test_schedule(
${TEST_SCHEDULE}_${_conf}
TEST_FILES
${TEST_FILES_${_conf}}
SOLO
${SOLO_TESTS_${_conf}}
GROUP_SIZE
${PARALLEL_GROUP_SIZE})
endforeach()