From 0e69061ac137318c7017de9b54b9a3b6752507ce Mon Sep 17 00:00:00 2001 From: Anton Zhilin Date: Wed, 20 Dec 2023 19:59:00 +0300 Subject: [PATCH] feat tests: use userver requirements (#47) feat tests: use userver requirements Also, correct Makefile to support Ninja generator (avoid direct usage of low-level make). --- .github/workflows/docker.yaml | 2 +- .gitignore | 6 ++- CMakeLists.txt | 19 ++++++++-- Makefile | 71 +++++++++++++++++------------------ Makefile.local | 1 - configs/static_config.yaml | 3 +- docker-compose.yml | 2 +- tests/requirements.txt | 2 - third_party/userver | 2 +- 9 files changed, 58 insertions(+), 50 deletions(-) delete mode 100644 Makefile.local delete mode 100644 tests/requirements.txt diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 379fac6..8db58d0 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -10,7 +10,7 @@ name: Docker build - feature/** env: - CMAKE_OPTIONS: -DUserverGrpc_VERSION=1.51.0 + CMAKE_COMMON_FLAGS: -DUserverGrpc_VERSION=1.51.0 jobs: tests: diff --git a/.gitignore b/.gitignore index dae3a68..0cb2684 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,12 @@ __pycache__ build* compile_commands.json .cache/ -.ccache/ .idea/ .vscode/ -.pgdata/ .cores/ +.ccache/ +.pgdata/ cmake-build-* Testing/ +.DS_Store +Makefile.local diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b33aee..098969c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,22 @@ cmake_minimum_required(VERSION 3.12) project(pg_service_template CXX) +# Disable userver libraries that are not needed in this project +set(USERVER_FEATURE_MONGODB OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_REDIS OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_CLICKHOUSE OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_GRPC OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_RABBITMQ OFF CACHE BOOL "" FORCE) + +# Compatibility mode: some systems don't support these features +set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE) +set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE) + + +# Adding userver dependency include(third_party/userver/cmake/SetupEnvironment.cmake) include(GNUInstallDirs) - add_subdirectory(third_party/userver) @@ -39,9 +52,7 @@ add_google_benchmark_tests(${PROJECT_NAME}_benchmark) # Functional Tests include(UserverTestsuite) -userver_testsuite_add_simple( - REQUIREMENTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/requirements.txt" -) +userver_testsuite_add_simple() # Install diff --git a/Makefile b/Makefile index 7962818..5713a79 100644 --- a/Makefile +++ b/Makefile @@ -1,69 +1,66 @@ CMAKE_COMMON_FLAGS ?= -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMAKE_DEBUG_FLAGS ?= -DUSERVER_SANITIZE='addr ub' CMAKE_RELEASE_FLAGS ?= -CMAKE_OS_FLAGS ?= -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 -DUSERVER_FEATURE_REDIS_HI_MALLOC=1 NPROCS ?= $(shell nproc) CLANG_FORMAT ?= clang-format DOCKER_COMPOSE ?= docker-compose -# NOTE: use Makefile.local for customization +# NOTE: use Makefile.local to override the options defined above. -include Makefile.local +CMAKE_DEBUG_FLAGS += -DCMAKE_BUILD_TYPE=Debug $(CMAKE_COMMON_FLAGS) +CMAKE_RELEASE_FLAGS += -DCMAKE_BUILD_TYPE=Release $(CMAKE_COMMON_FLAGS) + .PHONY: all all: test-debug test-release -# Debug cmake configuration -build_debug/Makefile: - @git submodule update --init - @mkdir -p build_debug - @cd build_debug && \ - cmake -DCMAKE_BUILD_TYPE=Debug $(CMAKE_COMMON_FLAGS) $(CMAKE_DEBUG_FLAGS) $(CMAKE_OS_FLAGS) $(CMAKE_OPTIONS) .. +# Run cmake +.PHONY: cmake-debug +cmake-debug: + git submodule update --init + cmake -B build_debug $(CMAKE_DEBUG_FLAGS) -# Release cmake configuration -build_release/Makefile: - @git submodule update --init - @mkdir -p build_release - @cd build_release && \ - cmake -DCMAKE_BUILD_TYPE=Release $(CMAKE_COMMON_FLAGS) $(CMAKE_RELEASE_FLAGS) $(CMAKE_OS_FLAGS) $(CMAKE_OPTIONS) .. +.PHONY: cmake-release +cmake-release: + git submodule update --init + cmake -B build_release $(CMAKE_RELEASE_FLAGS) -# Run cmake -.PHONY: cmake-debug cmake-release -cmake-debug cmake-release: cmake-%: build_%/Makefile +build_debug/CMakeCache.txt: cmake-debug +build_release/CMakeCache.txt: cmake-release # Build using cmake .PHONY: build-debug build-release -build-debug build-release: build-%: cmake-% - @cmake --build build_$* -j $(NPROCS) --target pg_service_template +build-debug build-release: build-%: build_%/CMakeCache.txt + cmake --build build_$* -j $(NPROCS) --target pg_service_template # Test .PHONY: test-debug test-release test-debug test-release: test-%: build-% - @cmake --build build_$* -j $(NPROCS) --target pg_service_template_unittest - @cmake --build build_$* -j $(NPROCS) --target pg_service_template_benchmark - @cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V) - @pep8 tests + cmake --build build_$* -j $(NPROCS) --target pg_service_template_unittest + cmake --build build_$* -j $(NPROCS) --target pg_service_template_benchmark + cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V) + pep8 tests # Start the service (via testsuite service runner) .PHONY: service-start-debug service-start-release service-start-debug service-start-release: service-start-%: build-% - @cd ./build_$* && $(MAKE) start-pg_service_template + cmake --build build_$* -v --target start-pg_service_template # Cleanup data .PHONY: clean-debug clean-release clean-debug clean-release: clean-%: - cd build_$* && $(MAKE) clean + cmake --build build_$* --target clean .PHONY: dist-clean dist-clean: - @rm -rf build_* - @rm -rf tests/__pycache__/ - @rm -rf tests/.pytest_cache/ + rm -rf build_* + rm -rf tests/__pycache__/ + rm -rf tests/.pytest_cache/ # Install .PHONY: install-debug install-release install-debug install-release: install-%: build-% - @cd build_$* && \ - cmake --install . -v --component pg_service_template + cmake --install build_$* -v --component pg_service_template .PHONY: install install: install-release @@ -71,20 +68,20 @@ install: install-release # Format the sources .PHONY: format format: - @find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i - @find tests -name '*.py' -type f | xargs autopep8 -i + find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i + find tests -name '*.py' -type f | xargs autopep8 -i # Internal hidden targets that are used only in docker environment --in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-% - @psql 'postgresql://user:password@service-postgres:5432/pg_service_template_db-1' -f ./postgresql/data/initial_data.sql - @/home/user/.local/bin/pg_service_template \ + psql 'postgresql://user:password@service-postgres:5432/pg_service_template_db-1' -f ./postgresql/data/initial_data.sql + /home/user/.local/bin/pg_service_template \ --config /home/user/.local/etc/pg_service_template/static_config.yaml \ --config_vars /home/user/.local/etc/pg_service_template/config_vars.docker.yaml # Build and run service in docker environment .PHONY: docker-start-service-debug docker-start-service-release docker-start-service-debug docker-start-service-release: docker-start-service-%: - @$(DOCKER_COMPOSE) run -p 8080:8080 --rm pg_service_template-container make -- --in-docker-start-$* + $(DOCKER_COMPOSE) run -p 8080:8080 --rm pg_service_template-container make -- --in-docker-start-$* # Start targets makefile in docker environment .PHONY: docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release @@ -94,5 +91,5 @@ docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docke # Stop docker container and remove PG data .PHONY: docker-clean-data docker-clean-data: - @$(DOCKER_COMPOSE) down -v - @rm -rf ./.pgdata + $(DOCKER_COMPOSE) down -v + rm -rf ./.pgdata diff --git a/Makefile.local b/Makefile.local deleted file mode 100644 index 116e079..0000000 --- a/Makefile.local +++ /dev/null @@ -1 +0,0 @@ -CMAKE_COMMON_FLAGS += -DUSERVER_FEATURE_CRYPTOPP_BLAKE=0 -DUSERVER_DOWNLOAD_PACKAGE_CRYPTOPP=1 -DUSERVER_FEATURE_GRPC_CHANNELZ=0 diff --git a/configs/static_config.yaml b/configs/static_config.yaml index 57da1ad..9100be7 100644 --- a/configs/static_config.yaml +++ b/configs/static_config.yaml @@ -59,7 +59,8 @@ components_manager: dbconnection: $dbconnection blocking_task_processor: fs-task-processor dns_resolver: async - sync-start: true + sync-start: false + connlimit_mode: manual dns-client: fs-task-processor: fs-task-processor diff --git a/docker-compose.yml b/docker-compose.yml index afe0420..0e00dd5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,7 +34,7 @@ services: - CORES_DIR=/cores - CXX - MAKE_OPTS - - CMAKE_OPTIONS + - CMAKE_COMMON_FLAGS volumes: - .:/pg_service_template:rw - ./third_party/userver/tools/docker:/tools:ro diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index 3fdc85f..0000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -yandex-taxi-testsuite[postgresql-binary] >= 0.1.17 -websockets >= 11.0.3 diff --git a/third_party/userver b/third_party/userver index 9466ff0..06b5dfa 160000 --- a/third_party/userver +++ b/third_party/userver @@ -1 +1 @@ -Subproject commit 9466ff0b451a75d0ffb3eef9eb300cd12061eafb +Subproject commit 06b5dfa5c7951c956c3f3ed5d737a50c88c68f62