Skip to content

Commit dbd556d

Browse files
authored
feat tests: use userver requirements (#27)
Also, correct Makefile to support Ninja generator (avoid direct usage of low-level make).
1 parent 3946347 commit dbd556d

File tree

9 files changed

+58
-66
lines changed

9 files changed

+58
-66
lines changed

.github/workflows/docker.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: Docker build
1010
- feature/**
1111

1212
env:
13-
CMAKE_OPTIONS: -DUserverGrpc_VERSION=1.51.0
13+
CMAKE_COMMON_FLAGS: -DUserverGrpc_VERSION=1.51.0
1414

1515
jobs:
1616
tests:

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ __pycache__
22
build*
33
compile_commands.json
44
.cache/
5-
.ccache/
65
.idea/
76
.vscode/
8-
.pgdata/
97
.cores/
8+
.ccache/
9+
.pgdata/
1010
cmake-build-*
1111
Testing/
12+
.DS_Store
13+
Makefile.local

CMakeLists.txt

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(pg_grpc_service_template CXX)
33

4+
# Disable userver libraries that are not needed in this project
5+
set(USERVER_FEATURE_MONGODB OFF CACHE BOOL "" FORCE)
6+
set(USERVER_FEATURE_REDIS OFF CACHE BOOL "" FORCE)
7+
set(USERVER_FEATURE_CLICKHOUSE OFF CACHE BOOL "" FORCE)
8+
set(USERVER_FEATURE_RABBITMQ OFF CACHE BOOL "" FORCE)
9+
10+
# Compatibility mode: some systems don't support these features
11+
set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE)
12+
set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE)
13+
set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE)
14+
15+
16+
# Adding userver dependency
417
include(third_party/userver/cmake/SetupEnvironment.cmake)
518
include(GNUInstallDirs)
6-
719
add_subdirectory(third_party/userver)
820

921

@@ -45,19 +57,7 @@ add_google_benchmark_tests(${PROJECT_NAME}_benchmark)
4557
# Functional Tests
4658
include(UserverTestsuite)
4759

48-
set(testsuite_requirements "${CMAKE_CURRENT_SOURCE_DIR}/tests/requirements.txt")
49-
if(Protobuf_VERSION VERSION_GREATER 3.20.0)
50-
list(APPEND testsuite_requirements
51-
"${USERVER_DIR}/testsuite/requirements-grpc.txt")
52-
else()
53-
list(APPEND testsuite_requirements
54-
"${USERVER_DIR}/testsuite/requirements-grpc-old.txt")
55-
message(STATUS "Forcing old protobuf version for testsuite")
56-
endif()
57-
58-
userver_testsuite_add_simple(
59-
REQUIREMENTS ${testsuite_requirements}
60-
)
60+
userver_testsuite_add_simple()
6161

6262

6363
# Install

Makefile

+34-37
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,87 @@
11
CMAKE_COMMON_FLAGS ?= -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
22
CMAKE_DEBUG_FLAGS ?= -DUSERVER_SANITIZE='addr ub'
33
CMAKE_RELEASE_FLAGS ?=
4-
CMAKE_OS_FLAGS ?= -DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0 -DUSERVER_FEATURE_REDIS_HI_MALLOC=1
54
NPROCS ?= $(shell nproc)
65
CLANG_FORMAT ?= clang-format
76
DOCKER_COMPOSE ?= docker-compose
87

9-
# NOTE: use Makefile.local for customization
8+
# NOTE: use Makefile.local to override the options defined above.
109
-include Makefile.local
1110

11+
CMAKE_DEBUG_FLAGS += -DCMAKE_BUILD_TYPE=Debug $(CMAKE_COMMON_FLAGS)
12+
CMAKE_RELEASE_FLAGS += -DCMAKE_BUILD_TYPE=Release $(CMAKE_COMMON_FLAGS)
13+
1214
.PHONY: all
1315
all: test-debug test-release
1416

15-
# Debug cmake configuration
16-
build_debug/Makefile:
17-
@git submodule update --init
18-
@mkdir -p build_debug
19-
@cd build_debug && \
20-
cmake -DCMAKE_BUILD_TYPE=Debug $(CMAKE_COMMON_FLAGS) $(CMAKE_DEBUG_FLAGS) $(CMAKE_OS_FLAGS) $(CMAKE_OPTIONS) ..
17+
# Run cmake
18+
.PHONY: cmake-debug
19+
cmake-debug:
20+
git submodule update --init
21+
cmake -B build_debug $(CMAKE_DEBUG_FLAGS)
2122

22-
# Release cmake configuration
23-
build_release/Makefile:
24-
@git submodule update --init
25-
@mkdir -p build_release
26-
@cd build_release && \
27-
cmake -DCMAKE_BUILD_TYPE=Release $(CMAKE_COMMON_FLAGS) $(CMAKE_RELEASE_FLAGS) $(CMAKE_OS_FLAGS) $(CMAKE_OPTIONS) ..
23+
.PHONY: cmake-release
24+
cmake-release:
25+
git submodule update --init
26+
cmake -B build_release $(CMAKE_RELEASE_FLAGS)
2827

29-
# Run cmake
30-
.PHONY: cmake-debug cmake-release
31-
cmake-debug cmake-release: cmake-%: build_%/Makefile
28+
build_debug/CMakeCache.txt: cmake-debug
29+
build_release/CMakeCache.txt: cmake-release
3230

3331
# Build using cmake
3432
.PHONY: build-debug build-release
35-
build-debug build-release: build-%: cmake-%
36-
@cmake --build build_$* -j $(NPROCS) --target pg_grpc_service_template
33+
build-debug build-release: build-%: build_%/CMakeCache.txt
34+
cmake --build build_$* -j $(NPROCS) --target pg_grpc_service_template
3735

3836
# Test
3937
.PHONY: test-debug test-release
4038
test-debug test-release: test-%: build-%
41-
@cmake --build build_$* -j $(NPROCS) --target pg_grpc_service_template_unittest
42-
@cmake --build build_$* -j $(NPROCS) --target pg_grpc_service_template_benchmark
43-
@cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V)
44-
@pep8 tests
39+
cmake --build build_$* -j $(NPROCS) --target pg_grpc_service_template_unittest
40+
cmake --build build_$* -j $(NPROCS) --target pg_grpc_service_template_benchmark
41+
cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V)
42+
pep8 tests
4543

4644
# Start the service (via testsuite service runner)
4745
.PHONY: service-start-debug service-start-release
4846
service-start-debug service-start-release: service-start-%: build-%
49-
@cd ./build_$* && $(MAKE) start-pg_grpc_service_template
47+
cmake --build build_$* -v --target start-pg_grpc_service_template
5048

5149
# Cleanup data
5250
.PHONY: clean-debug clean-release
5351
clean-debug clean-release: clean-%:
54-
cd build_$* && $(MAKE) clean
52+
cmake --build build_$* --target clean
5553

5654
.PHONY: dist-clean
5755
dist-clean:
58-
@rm -rf build_*
59-
@rm -rf tests/__pycache__/
60-
@rm -rf tests/.pytest_cache/
56+
rm -rf build_*
57+
rm -rf tests/__pycache__/
58+
rm -rf tests/.pytest_cache/
6159

6260
# Install
6361
.PHONY: install-debug install-release
6462
install-debug install-release: install-%: build-%
65-
@cd build_$* && \
66-
cmake --install . -v --component pg_grpc_service_template
63+
cmake --install build_$* -v --component pg_grpc_service_template
6764

6865
.PHONY: install
6966
install: install-release
7067

7168
# Format the sources
7269
.PHONY: format
7370
format:
74-
@find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i
75-
@find tests -name '*.py' -type f | xargs autopep8 -i
71+
find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i
72+
find tests -name '*.py' -type f | xargs autopep8 -i
7673

7774
# Internal hidden targets that are used only in docker environment
7875
--in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-%
79-
@psql 'postgresql://user:password@service-postgres:5432/pg_grpc_service_template_db-1' -f ./postgresql/data/initial_data.sql
80-
@/home/user/.local/bin/pg_grpc_service_template \
76+
psql 'postgresql://user:password@service-postgres:5432/pg_grpc_service_template_db-1' -f ./postgresql/data/initial_data.sql
77+
/home/user/.local/bin/pg_grpc_service_template \
8178
--config /home/user/.local/etc/pg_grpc_service_template/static_config.yaml \
8279
--config_vars /home/user/.local/etc/pg_grpc_service_template/config_vars.docker.yaml
8380

8481
# Build and run service in docker environment
8582
.PHONY: docker-start-service-debug docker-start-service-release
8683
docker-start-service-debug docker-start-service-release: docker-start-service-%:
87-
@$(DOCKER_COMPOSE) run -p 8080:8080 --rm pg_grpc_service_template-container make -- --in-docker-start-$*
84+
$(DOCKER_COMPOSE) run -p 8080:8080 --rm pg_grpc_service_template-container make -- --in-docker-start-$*
8885

8986
# Start targets makefile in docker environment
9087
.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
9491
# Stop docker container and remove PG data
9592
.PHONY: docker-clean-data
9693
docker-clean-data:
97-
@$(DOCKER_COMPOSE) down -v
98-
@rm -rf ./.pgdata
94+
$(DOCKER_COMPOSE) down -v
95+
rm -rf ./.pgdata

Makefile.local

-7
This file was deleted.

configs/static_config.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ components_manager:
99

1010
grpc-blocking-task-processor:
1111
worker_threads: $worker-grpc-threads
12+
thread_name: grpc-worker
1213

1314
default_task_processor: main-task-processor
1415

@@ -77,7 +78,8 @@ components_manager:
7778
dbconnection: $dbconnection
7879
blocking_task_processor: fs-task-processor
7980
dns_resolver: async
80-
sync-start: true
81+
sync-start: false
82+
connlimit_mode: manual
8183

8284
dns-client:
8385
fs-task-processor: fs-task-processor

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ services:
3434
- CORES_DIR=/cores
3535
- CXX
3636
- MAKE_OPTS
37-
- CMAKE_OPTIONS
37+
- CMAKE_COMMON_FLAGS
3838
volumes:
3939
- .:/pg_grpc_service_template:rw
4040
- ./third_party/userver/tools/docker:/tools:ro

tests/requirements.txt

-2
This file was deleted.

third_party/userver

Submodule userver updated 598 files

0 commit comments

Comments
 (0)