Skip to content

Commit

Permalink
#173 Migratig integration tests to OSS repo
Browse files Browse the repository at this point in the history
* Python modules

Signed-off-by: Jean-Louis Leroy <[email protected]>

* Integration tests

Signed-off-by: Jean-Louis Leroy <[email protected]>

* rename

Signed-off-by: Jean-Louis Leroy <[email protected]>

* simplify

Signed-off-by: Jean-Louis Leroy <[email protected]>

* adapt tests

Signed-off-by: Jean-Louis Leroy <[email protected]>

* workspace -> configurator

Signed-off-by: Jean-Louis Leroy <[email protected]>

* build.yaml

Signed-off-by: Jean-Louis Leroy <[email protected]>

---------

Signed-off-by: Jean-Louis Leroy <[email protected]>
  • Loading branch information
jll63 authored Jan 24, 2024
1 parent b3ddcc5 commit 3bdaf5a
Show file tree
Hide file tree
Showing 71 changed files with 18,594 additions and 12 deletions.
41 changes: 29 additions & 12 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:

jobs:
build_and_test:
name: "Check if BlazingMQ can build and pass unit tests"
name: "Check if BlazingMQ can build, and pass unit and integration tests"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -25,13 +25,15 @@ jobs:
gdb \
curl \
python3.10 \
python3-pip \
cmake \
ninja-build \
pkg-config \
bison \
libfl-dev \
libbenchmark-dev \
libz-dev
pip install -r ${{ github.workspace }}/src/python/requirements.txt
- name: Create dependency fetcher working directory
run: mkdir -p deps
- name: Fetch & Build non packaged dependencies
Expand All @@ -41,23 +43,38 @@ jobs:
env:
PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/opt/bb/lib64/pkgconfig
run: |
cmake -S . -B cmake.bld/Linux -G Ninja \
cmake -S . -B build/blazingmq -G Ninja \
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/deps/srcs/bde-tools/BdeBuildSystem/toolchains/linux/gcc-default.cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DBDE_BUILD_TARGET_SAFE=ON \
-DBDE_BUILD_TARGET_64=ON \
-DBDE_BUILD_TARGET_CPP17=ON \
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/deps/srcs/bde-tools/BdeBuildSystem \
-DCMAKE_INSTALL_LIBDIR=lib64
cmake --build cmake.bld/Linux --parallel 8 --target all all.t
- name: Run Unit Tests
cmake --build build/blazingmq --parallel 8 --target all all.t
- name: Run C++ Unit Tests
run: |
cd cmake.bld/Linux
cd build/blazingmq
ctest -E mwcsys_executil.t --output-on-failure
- name: Run Python Unit Tests
run: |
pytest src/python
- name: Run Integration Tests
run: |
${{ github.workspace }}/src/integration-tests/run-tests \
--log-level ERROR \
--log-file-level=info \
--bmq-tolerate-dirty-shutdown \
--bmq-log-dir=failure-logs \
--bmq-log-level=INFO \
--junitxml=integration-tests.xml \
--tb line \
--reruns=3 \
-n 4 -v
- uses: actions/cache@v3
with:
path: |
cmake.bld/Linux
build/blazingmq
deps
/opt/bb/include
key: cache-${{ github.sha }}
Expand All @@ -71,7 +88,7 @@ jobs:
- uses: actions/cache/@v3
with:
path: |
cmake.bld/Linux
build/blazingmq
deps
/opt/bb/include
key: cache-${{ github.sha }}
Expand Down Expand Up @@ -100,7 +117,7 @@ jobs:
env:
PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig:/opt/bb/lib64/pkgconfig
run: |
cmake -S . -B cmake.bld/Linux -G Ninja \
cmake -S . -B build/blazingmq -G Ninja \
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/deps/srcs/bde-tools/BdeBuildSystem/toolchains/linux/gcc-default.cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DBDE_BUILD_TARGET_SAFE=ON \
Expand All @@ -109,7 +126,7 @@ jobs:
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/deps/srcs/bde-tools/BdeBuildSystem \
-DCMAKE_INSTALL_LIBDIR=lib64 \
-DINSTALL_TARGETS=prometheus
cmake --build cmake.bld/Linux --parallel 8 --target all
cmake --build build/blazingmq --parallel 8 --target all
- name: Create prometheus dir
run: mkdir -p prometheus_dir
- name: Download Prometheus
Expand All @@ -121,14 +138,14 @@ jobs:
docker pull prom/pushgateway
docker run -d -p 9091:9091 prom/pushgateway
- name: Run BMQPrometheus plugin integration test in "pull" mode
run: ${{ github.workspace }}/src/plugins/bmqprometheus/tests/bmqprometheus_prometheusstatconsumer_test.py -p ${{ github.workspace }}/cmake.bld/Linux -m pull --no-docker
run: ${{ github.workspace }}/src/plugins/bmqprometheus/tests/bmqprometheus_prometheusstatconsumer_test.py -p ${{ github.workspace }}/build/blazingmq -m pull --no-docker
- name: Clear Prometheus database and restart
run: |
curl -X POST "http://localhost:9090/-/quit"
rm -rf prometheus_dir/data
./prometheus_dir/prometheus-2.45.1.linux-amd64/prometheus --config.file=${{ github.workspace }}/src/plugins/bmqprometheus/tests/prometheus_localhost.yaml --web.enable-lifecycle --storage.tsdb.path=${{ github.workspace }}/prometheus_dir/data &
- name: Run Prometheus plugin integration test in "push" mode
run: ${{ github.workspace }}/src/plugins/bmqprometheus/tests/bmqprometheus_prometheusstatconsumer_test.py -p ${{ github.workspace }}/cmake.bld/Linux -m push --no-docker
run: ${{ github.workspace }}/src/plugins/bmqprometheus/tests/bmqprometheus_prometheusstatconsumer_test.py -p ${{ github.workspace }}/build/blazingmq -m push --no-docker

Documentation:
name: "Documentation"
Expand All @@ -142,7 +159,7 @@ jobs:
- name: Build docs
run: |
doxygen Doxyfile
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ CMakeUserPresets.json
/.vscode/
/include/
/lib/
**/__pycache__/
14 changes: 14 additions & 0 deletions src/integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# BlazingMQ Integration Tests

[WIP]

To run the tests:

* (create and) activate a Python 3.8 (or above) `venv`
* `python -m venv /path/to/venv`
* `source /path/to/venv/bin/activate`
* install required modules
* `pip install -r src/python/requirements.txt`
* run the tests
* `cd src/integration-tests`
* `./run-tests [extra pytest options]`
Empty file.
140 changes: 140 additions & 0 deletions src/integration-tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import contextlib
import logging
import pytest

import blazingmq.dev.it.logging
import blazingmq.util.logging as bul
from blazingmq.dev.pytest import PYTEST_LOG_SPEC_VAR


def pytest_addoption(parser):
# Do this here so the 'TRACE' level is available in the command line
# switches.
logging.TRACE = logging.DEBUG - 1
logging.addLevelName(logging.TRACE, "TRACE")

help_ = "put combined broker logs and client outputs for failed tests in DIR"
parser.addoption(
"--bmq-log-dir", dest="bmq_log_dir", action="store", metavar="DIR", help=help_
)
parser.addini("bmq_log_dir", help_, type=None, default=None)

help_ = "use POLICY in cluster configuration where available"
parser.addoption(
"--bmq-cluster-policy",
dest="bmq_cluster_policy",
action="store",
metavar="POLICY",
help=help_,
)
parser.addini("bmq_cluster_policy", help_, type=None, default=None)

help_ = "tack ARGS at the end of the bmqbrkr command line"
parser.addoption(
"--bmq-broker-extra-args",
dest="bmq_broker_extra_args",
action="store",
metavar="ARGS",
help=help_,
)
parser.addini("bmq_broker_extra_args", help_, type=None, default=None)

help_ = "always keep logs"
parser.addoption(
"--bmq-keep-logs",
dest="bmq_keep_logs",
action="store_true",
default=False,
help=help_,
)
parser.addini("bmq_keep_logs", help_, type=None, default=None)

help_ = "do not delete work directory after test finishes"
parser.addoption(
"--bmq-keep-work-dirs",
dest="bmq_keep_work_dirs",
action="store_true",
default=False,
help=help_,
)
parser.addini("bmq_keep_work_dirs", help_, type=None, default=None)

help_ = "break before test begins - NOTE: requires -s, no docker, no parallelism"
parser.addoption(
"--bmq-break-before-test",
dest="bmq_break_before_test",
action="store_true",
default=False,
help=help_,
)

help_ = "do not report process crashes or errors during shutdown"
parser.addoption(
"--bmq-tolerate-dirty-shutdown",
dest="bmq_tolerate_dirty_shutdown",
action="store_true",
default=False,
help=help_,
)
parser.addini("bmq_tolerate_dirty_shutdown", help_, type=None, default=False)

with contextlib.suppress(Exception):
help_ = "set per-category log level"
parser.addoption(
"--bmq-log-level",
dest=PYTEST_LOG_SPEC_VAR,
action="store",
default=[],
metavar="LEVEL",
help=help_,
)
parser.addini(PYTEST_LOG_SPEC_VAR, help_, type=None, default=None)

help_ = "run only with the specified order"
parser.addoption(
"--bmq-wave",
type=int,
action="store",
metavar="WAVE",
help=help_,
)


def pytest_configure(config):
logging.setLoggerClass(blazingmq.dev.it.logging.BMQLogger)

level_spec = config.getoption(PYTEST_LOG_SPEC_VAR) or config.getini(
PYTEST_LOG_SPEC_VAR
)

if level_spec:
levels = bul.normalize_log_levels(level_spec)
bul.apply_normalized_log_levels(levels)
top_level = levels[0]
logging.getLogger("proc").setLevel(top_level)
logging.getLogger("test").setLevel(top_level)


def pytest_collection_modifyitems(config, items):
active_wave = config.getoption("bmq_wave")
if active_wave is None:
return

for item in items:
mark = None
for mark in item.iter_markers(name="order"):
pass

if mark is None:
order = 0
else:
order = int(mark.args[0])

if order == active_wave:
continue

item.add_marker(
pytest.mark.skip(
reason=f"order = {order}, running {active_wave} only"
)
)
2 changes: 2 additions & 0 deletions src/integration-tests/pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MASTER]
disable=attribute-defined-outside-init,disallowed-name,duplicate-code,fixme,invalid-name,line-too-long,missing-class-docstring,missing-function-docstring,missing-module-docstring,redefined-outer-name,too-few-public-methods,too-many-arguments,too-many-branches,too-many-instance-attributes,too-many-lines,too-many-locals,too-many-public-methods,too-many-statements
18 changes: 18 additions & 0 deletions src/integration-tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[pytest]
log_cli_format = %(bmqprocess)-16s %(filename)s:%(lineno)d %(message)s
log_level = INFO
log_format = %(bmqprocess16)s %(asctime)s.%(msecs)03d (%(thread)15d) %(levelname)-8s %(name24)s %(filename)10s:%(lineno)-03d %(message)s
log_file_format = %(bmqprocess16)s %(asctime)s.%(msecs)03d (%(thread)15d) %(levelname)-8s %(name24)s %(filename)10s:%(lineno)-03d %(message)s
log_file_level = INFO
log_file_date_format = %d%b%Y_%H:%M:%S
addopts = --strict-markers -p no:cacheprovider
junit_family = legacy
markers =
integrationtest
quick_integrationtest
pr_integrationtest
single
multi
csl_mode
fsm_mode
flakey
11 changes: 11 additions & 0 deletions src/integration-tests/run-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env bash

set -e

repo_dir=$(realpath "$0")
repo_dir=${repo_dir%/src/*}

export PYTHONPATH=$repo_dir/src/python:$PYTHONPATH
cd "$repo_dir/src/integration-tests"

python -m pytest -m "not csl_mode and not fsm_mode" "$@"
43 changes: 43 additions & 0 deletions src/integration-tests/test_admin_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
This suite of test cases exercises admin session connection and some basic
commands.
"""

import json
import re

from blazingmq.dev.it.fixtures import Cluster, single_node, order # pylint: disable=unused-import
from blazingmq.dev.it.process.admin import AdminClient


def test_admin(single_node: Cluster):
cluster: Cluster = single_node
endpoint: str = cluster.config.definition.nodes[0].transport.tcp.endpoint # type: ignore

# Extract the (host, port) pair from the config
m = re.match(r".+://(.+):(\d+)", endpoint) # tcp://host:port
assert m is not None
host, port = str(m.group(1)), int(m.group(2))

# Start the admin client
admin = AdminClient()
admin.connect(host, port)

# Check basic "help" command
assert (
"This process responds to the following CMD subcommands:"
in admin.send_admin("help")
)

# Check non-existing "invalid cmd" command
assert "Unable to decode command" in admin.send_admin("invalid cmd")

# Check more complex "brokerconfig dump" command, expect valid json
# with the same "port" value as the one used for this connection
broker_config_str = admin.send_admin("brokerconfig dump")
broker_config = json.loads(broker_config_str)

assert broker_config["networkInterfaces"]["tcpInterface"]["port"] == port

# Stop the admin session
admin.stop()
Loading

0 comments on commit 3bdaf5a

Please sign in to comment.