Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option (ENABLE_ZK "Build with ZooKeeper support" ON)
option (ENABLE_ETCD "Build with etcd support" ON)
option (ENABLE_CONSUL "Build with Consul support" ON)
option (BUILD_TESTS "Build library tests" ON)
option (BUILD_ENV_TESTS "Build environment dependent library tests" OFF)
option (BUILD_CLIB "Build C library" OFF)
set(SANITIZE "" CACHE STRING "Build tests with sanitizer")

Expand Down Expand Up @@ -65,7 +66,7 @@ if (ENABLE_ETCD)
list (APPEND SERVICE_TEST_ADDRESSES "etcd://localhost:2379")
endif ()

if (BUILD_TESTS)
if (BUILD_TESTS OR BUILD_ENV_TESTS)
# google tests
enable_testing ()
add_subdirectory (tests)
Expand Down
13 changes: 13 additions & 0 deletions env-tests/Dockerfile-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ARG parent
FROM $parent

COPY . /test/app
WORKDIR /test/app

ARG cmake_generate_args=""
ARG cmake_build_args=""
ARG generate_cmd="cmake -DCMAKE_TOOLCHAIN_FILE=/test/vcpkg/scripts/buildsystems/vcpkg.cmake $cmake_generate_args ."
ARG build_cmd="cmake --build $cmake_build_args ."

RUN $generate_cmd
RUN $build_cmd
69 changes: 69 additions & 0 deletions env-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
testenv
=======

testenv is a docker-based environment manager for advanced testing.

## Why testenv?

Most cases can be covered with unit tests assuming the services are started locally. However, it is also worth testing not only how the library handles its own actions but how it responds to external conditions like connection loss.

It means that tests must not only interact with the library but affect the environment. You probably don't want to break the networking of your workstation. Here testenv comes in.

## Components

testenv consists of

- third-party service images with ZooKeeper, Consul and etcd
- base image with vcpkg and precompiled liboffkv dependencies
- bash script to govern them all

As you work with testenv, more components appear:

- testing images
- service containers
- testing containers

## Workflow

```sh
# print usage info
testenv

# download service images and build base image
# it will take some time
testenv prepare

# start 3 clusters 3 nodes each
testenv run -nzk:3 -netcd:3 -nconsul:3

# print running testenv entities
testenv status

# run tests against the clusters
# see details below
testenv test -d /path/to/liboffkv -g -DBUILD_ENV_TESTS=ON -r tests/conn_test

# stop all running testenv entities
testenv stop

# remove all testenv containers and testing images
testenv clear

# remove all testenv containers and images
testenv clear -a
docker system prune
```

`testenv test` will actually

- Build an image with the contents from directory specified with `-d`. The directory may not contain Dockerfile. testenv provides the default one. However, custom Dockerfile can be used for more precise control.
- Inside the container it normally executes
- `cmake -DCMAKE_TOOLCHAIN_FILE=/p/to/vcpkg.cmake .`; additional arguments can be passed with `-g`.
- `cmake --build .`; ; additional arguments can be passed with `-b`, e.g. `-g --target test_etcd`.
- This behavior can be overridden by passing `generate_cmd=cmd`, `build_cmd=cmd`.
- Form a list of addresses for each service.
- Sequentially run containers with the image for each service in interactive mode. The container will receive the command passed via `-r` concatenated with the list of addresses.

## Introducing conditions

Default base image for tests has `iptables` bundled. Testing are run with `--cap-add NET_ADMIN`. Thus all the power of `iptables` can be used to manipulate networking directly from the tests.
12 changes: 12 additions & 0 deletions env-tests/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM debian:buster-slim

ENV VCPKG_ROOT=/test/vcpkg CXX=/usr/bin/g++-8

RUN apt-get update && apt-get install -y g++-8 make cmake git curl unzip tar iptables
RUN mkdir /test
RUN git clone --single-branch --branch=master --depth=1 'https://github.com/Microsoft/vcpkg' "$VCPKG_ROOT"

WORKDIR "$VCPKG_ROOT"
RUN ./bootstrap-vcpkg.sh -disableMetrics
RUN ./vcpkg install gtest ppconsul zkpp offscale-libetcd-cpp && rm -rf buildtrees/*
WORKDIR /test
8 changes: 8 additions & 0 deletions env-tests/naming.def.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# don't change the 'nameing.def.conf' file
# create 'naming.conf' instead and override needed variables

NETWORK="offkv"
TEST_BASE_IMAGE="offkv-test-base"
SERVICE_CONTAINER_PREFIX="offkv-s-"
TESTING_CONTAINER_PREFIX="offkv-t-"
TESTING_IMAGE_PREFIX="offkv-t-"
Loading