Skip to content

Commit

Permalink
feat tests: use userver requirements (#47)
Browse files Browse the repository at this point in the history
feat tests: use userver requirements

Also, correct Makefile to support Ninja generator (avoid direct usage of low-level make).
  • Loading branch information
Anton3 authored Dec 20, 2023
1 parent 3626c76 commit 0e69061
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ __pycache__
build*
compile_commands.json
.cache/
.ccache/
.idea/
.vscode/
.pgdata/
.cores/
.ccache/
.pgdata/
cmake-build-*
Testing/
.DS_Store
Makefile.local
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)


Expand Down Expand Up @@ -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
Expand Down
71 changes: 34 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,90 +1,87 @@
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

# 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
Expand All @@ -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
1 change: 0 additions & 1 deletion Makefile.local

This file was deleted.

3 changes: 2 additions & 1 deletion configs/static_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion third_party/userver
Submodule userver updated 598 files

0 comments on commit 0e69061

Please sign in to comment.