Skip to content

Commit e1d804b

Browse files
Some fixes for local run of tests (#53)
1 parent e27234e commit e1d804b

File tree

6 files changed

+46
-37
lines changed

6 files changed

+46
-37
lines changed

CONTRIBUTING.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Fork, Clone, Branch and Create your PR
44

55
When cloning the repo, you have to initialize the submodules:
6+
67
```sh
78
git submodule update --init --recursive
89
```
@@ -21,24 +22,35 @@ git submodule update --init --recursive
2122
| `python` | 3.0+ | |
2223
| `cmake` | 3.12+ | |
2324

24-
Once you got a valid `python` installation, install all the dependencies with
25+
Once you got a valid Python installation, install all the dependencies with:
2526

26-
````shell
27+
```sh
2728
pip install -r requirements.txt
28-
````
29+
```
2930

3031
## Compiling
3132

3233
### Setup `httpd`
3334

34-
In order to build the module you have to configure `httpd` with the [scripts/setup-httpd.py](./scripts/setup-httpd.py) script:
35+
In order to build the module you have to configure `httpd` with the [scripts/setup-httpd.py](./scripts/setup-httpd.py) script. Check what is the latest available version on [Apache website](https://httpd.apache.org), then:
3536

3637
```sh
37-
python scripts/setup-httpd.py -o httpd $HTTPD_VERSION
38+
export HTTPD_VERSION=2.4.66
39+
python scripts/setup-httpd.py $HTTPD_VERSION
3840
cd httpd
3941
./configure --with-included-apr --prefix=$(pwd)/httpd-build --enable-mpms-shared="all"
4042
```
4143

44+
### Install Rust
45+
46+
The RUM variant requires Rust to build:
47+
48+
```sh
49+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
50+
```
51+
52+
Relaunch your terminal (or do `source ~/.cargo/env`).
53+
4254
### Build the Module
4355

4456
CMake is our build system. If you are not familiar with CMake, read [the tutorial.](https://cmake.org/cmake/help/latest/guide/tutorial/index.html)

cmake/deps/fmt.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ if(NOT fmt_POPULATED)
1313
set(BUILD_SHARED_LIBS OFF)
1414
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1515

16-
add_subdirectory(${fmt_SOURCE_DIR} EXCLUDE_FROM_ALL)
16+
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR} EXCLUDE_FROM_ALL)
1717
endif()
1818

scripts/setup-httpd.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def main():
7272
args = parser.parse_args()
7373

7474
args.output = os.path.abspath(args.output)
75+
if os.path.exists(args.output):
76+
print(f"Output directory '{args.output}' already exists. Please remove it before running this script.")
77+
return 1
7578

7679
if not subprocess.run("git -v", shell=True, stdout=subprocess.DEVNULL):
7780
print("git command must be available")

test/integration-test/README.md

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ Integration tests for Apache httpd Datadog module using pytest.
44

55
## Quick Start
66

7-
### Prerequisites
8-
9-
For local testing, install Apache development packages:
10-
```bash
11-
# Ubuntu/Debian
12-
sudo apt-get install apache2 apache2-dev libapr1-dev libaprutil1-dev
13-
14-
# macOS
15-
brew install httpd
16-
```
17-
187
### Setup
198

209
```bash
@@ -24,19 +13,25 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
2413
# Install test dependencies
2514
cd test/integration-test && uv sync
2615

27-
# Run all tests (auto-builds module variants as needed)
28-
uv run pytest --bin-path=/usr/sbin/apachectl -v
16+
# Run smoke tests (auto-builds module variants as needed)
17+
uv run pytest --bin-path=../../httpd/httpd-build/bin/apachectl -v -m smoke
18+
19+
# Run CI tests
20+
uv run pytest --bin-path=../../httpd/httpd-build/bin/apachectl -v -m ci
2921

3022
# Run RUM tests only (auto-builds with RUM support)
31-
uv run pytest --bin-path=/usr/sbin/apachectl -m requires_rum -v
23+
uv run pytest --bin-path=../../httpd/httpd-build/bin/apachectl -v -m requires_rum
24+
25+
# Run all tests (auto-builds module variants as needed)
26+
uv run pytest --bin-path=../../httpd/httpd-build/bin/apachectl -v
3227

3328
# Run with pre-built module (skip auto-build)
34-
uv run pytest --bin-path=/usr/sbin/apachectl \
35-
--module-path=/path/to/mod_datadog.so -v
29+
uv run pytest --bin-path=../../httpd/httpd-build/bin/apachectl -v \
30+
--module-path=/path/to/mod_datadog.so
3631

3732
# Run specific test file
38-
uv run pytest --bin-path=/usr/sbin/apachectl \
39-
scenarios/test_rum.py -v
33+
uv run pytest --bin-path=../../httpd/httpd-build/bin/apachectl -v \
34+
scenarios/test_rum.py
4035
```
4136

4237
**Auto-Build Behavior:**
@@ -87,7 +82,7 @@ DatadogRum On
8782

8883
## Docker Testing
8984

90-
```bash
85+
```sh
9186
docker run --rm -v "$PWD:/workspace" -w /workspace \
9287
datadog/docker-library:httpd-datadog-ci-2.4-cdb3cb2 \
9388
sh -c "
@@ -105,12 +100,12 @@ docker run --rm -v "$PWD:/workspace" -w /workspace \
105100
**RUM build fails:** Check CMake output for missing dependencies (inject-browser-sdk is fetched automatically via CMake FetchContent)
106101

107102
**Tests hang:** Port 8136 in use
108-
```bash
103+
```sh
109104
lsof -i :8136
110105
```
111106

112107
**Module issues:**
113-
```bash
108+
```sh
114109
ldd /path/to/mod_datadog.so
115110
apachectl -f /path/to/config.conf -t
116111
```

test/integration-test/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,13 @@ def pytest_sessionstart(session: pytest.Session) -> None:
290290

291291
log_dir = session.config.getoption("--log-dir")
292292
if log_dir:
293+
log_dir = os.path.abspath(log_dir)
293294
if os.path.exists(log_dir):
294295
# TODO: Warn old logs will be removed and manage error
295296
shutil.rmtree(log_dir)
296297
os.mkdir(log_dir)
297298
else:
298-
log_dir = tempfile.mkdtemp(prefix="log-httpd-tests-", dir=".")
299+
log_dir = tempfile.mkdtemp(prefix="log-httpd-tests-")
299300

300301
session.config.log_dir = log_dir
301302

test/integration-test/pytest_plugins/integration_helpers.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def _build_module(
4747
# Configure
4848
print(f" Configuring CMake...")
4949
cmake_args = ["cmake", "-B", str(build_dir)]
50+
httpd_src_dir = project_root / "httpd"
51+
if httpd_src_dir.exists():
52+
cmake_args.append(f"-DHTTPD_SRC_DIR={httpd_src_dir}")
5053
if enable_rum:
5154
cmake_args.append("-DHTTPD_DATADOG_ENABLE_RUM=ON")
5255
cmake_args.append(".")
@@ -97,7 +100,7 @@ def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item
97100

98101
# Find project root
99102
test_dir = Path(__file__).parent.parent
100-
project_root = test_dir.parent.parent
103+
project_root = test_dir.parent.parent.resolve()
101104

102105
if not (project_root / "CMakeLists.txt").exists():
103106
pytest.exit("Cannot find project root CMakeLists.txt", returncode=1)
@@ -131,14 +134,9 @@ def pytest_sessionstart(session: pytest.Session) -> None:
131134
session.config.module_path = explicit_path
132135
return
133136

134-
# Otherwise, use the auto-built modules
135-
# Default to non-RUM module if both were built
136-
if session.config._module_paths.get("no_rum"):
137-
session.config.module_path = str(session.config._module_paths["no_rum"])
138-
elif session.config._module_paths.get("rum"):
139-
session.config.module_path = str(session.config._module_paths["rum"])
140-
else:
141-
pytest.exit("No module path available", returncode=1)
137+
# Module paths are populated later in pytest_collection_modifyitems (after collection).
138+
# Set a placeholder here; pytest_runtest_setup will assign the correct variant per test.
139+
session.config.module_path = None
142140

143141

144142
def pytest_runtest_setup(item: pytest.Item) -> None:

0 commit comments

Comments
 (0)