Skip to content
Merged
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
1 change: 0 additions & 1 deletion test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
__pycache__/
docker-compose-verbose.log
test.times
6 changes: 3 additions & 3 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Tests
=====
These are integration tests. They're written in python, and use
`docker-compose` to orchestrate an instance of nginx containing the module
`docker compose` to orchestrate an instance of nginx containing the module
under test, and other services reverse proxied by nginx.

See the readme file in [cases/](cases/) for usage information.
Expand All @@ -11,8 +11,8 @@ Files
- [bin/](bin/) contains scripts for running and developing the tests. Notably,
[bin/run](bin/run) runs the tests.
- [cases/](cases/) contains the actual python test cases that run tests against
the `docker-compose` setup.
- [services/](services/) contains the dockerfiles for the `docker-compose`
the `docker compose` setup.
- [services/](services/) contains the dockerfiles for the `docker compose`
services, and other data relevant to the services.
- [docker-compose.yaml](docker-compose.yml) defines the services used by the
tests.
2 changes: 1 addition & 1 deletion test/bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ These are scripts that are useful when working with the integration tests.
unittest`, so for example you can run a subset of tests, or increase the
verbosity of logging.
- [run_parallel](run_parallel) is a wrapper around [run](run) that executes
each test Python module in its own docker-compose "project," all in parallel.
each test Python module in its own docker compose "project," all in parallel.
2 changes: 1 addition & 1 deletion test/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export BASE_IMAGE
export NGINX_MODULES_PATH="${NGINX_MODULES_PATH:-/usr/lib/nginx/modules}"
export NGINX_CONF_PATH="${NGINX_CONF_PATH:-/etc/nginx/nginx.conf}"

docker-compose build --parallel
docker compose build --parallel
python3 -m unittest "$@"
4 changes: 2 additions & 2 deletions test/bin/run_parallel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [ "$BASE_IMAGE" = '' ]; then
fi

export NGINX_MODULES_PATH="${NGINX_MODULES_PATH:-/usr/lib/nginx/modules}"
docker-compose build --parallel
docker compose build --parallel

scratch=$(mktemp -d)
mkfifo "$scratch/pipe"
Expand All @@ -28,7 +28,7 @@ else
fi

while read -r i tests; do
echo "docker-compose project \"test$i\" will run the following: $tests"
echo "docker compose project \"test$i\" will run the following: $tests"
# shellcheck disable=SC2086
COMPOSE_PROJECT_NAME="test$i" python3 -m unittest "$@" $tests &
done <"$scratch/pipe"
Expand Down
20 changes: 10 additions & 10 deletions test/cases/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
These are the actual integration tests.

The tests run as python `unittest` test cases. They share an instance of
`class Orchestration`, which encapsulates the `docker-compose` services
session by running `docker-compose up` before any tests begin and by running
`docker-compose down` after all tests have completed.
`class Orchestration`, which encapsulates the `docker compose` services
session by running `docker compose up` before any tests begin and by running
`docker compose down` after all tests have completed.

Usage
-----
Expand Down Expand Up @@ -46,9 +46,9 @@ relevant. For example, to run only the test
$ test/bin/run cases.configuration.test_configuration
```

To see very detailed output, tail the `logs/docker-compose-verbose.log` file.
To see very detailed output, tail the `logs/test.log` file.
```console
$ touch logs/docker-compose-verbose.log && tail -f logs/docker-compose-verbose.log &
$ touch logs/test.log && tail -f logs/test.log &
$ test/bin/run
```

Expand Down Expand Up @@ -77,16 +77,16 @@ The `*.py` directly in this directory are common code shared by the tests.

- [case.py](case.py) is a wrapper around `unittest.TestCase` that provides an
attribute `.orch` of type `Orchestration`. Test cases can use this to share
a single scoped session of `docker-compose` services.
a single scoped session of `docker compose` services.
- [formats.py](formats.py) contains parsing functions for the output of
`docker-compose up`, `docker-compose down`, and the JSON-formatted
`docker compose up`, `docker compose down`, and the JSON-formatted
traces logged by the agent service.
- [lazy_singleton.py](lazy_singleton.py) defines a generic singleton class,
which is then used to define a single instance of `Orchestration`, the
`docker-compose` wrapper.
`docker compose` wrapper.
- [orchestration.py](orchestration.py) defines a `class Orchestration` that
manages a thread that runs and consumes the output of `docker-compose up`,
and has methods for performing operations on the `docker-compose` setup,
manages a thread that runs and consumes the output of `docker compose up`,
and has methods for performing operations on the `docker compose` setup,
e.g.
- sending a request to nginx,
- retrieving the logs of a service,
Expand Down
4 changes: 2 additions & 2 deletions test/cases/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def tearDown(self):

# `startTestRun` and `stopTestRun` are injected into the `unittest` module so
# that test suites that span multiple modules share a scoped instance of
# `Orchestration`, i.e. `docker-compose up` happens before any tests run,
# and `docker-compose down` happens after all tests are finished.
# `Orchestration`, i.e. `docker compose up` happens before any tests run,
# and `docker compose down` happens after all tests are finished.
#
# See <https://stackoverflow.com/a/64892396>.
global_orch_context = None
Expand Down
22 changes: 11 additions & 11 deletions test/cases/formats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""interpret the output of `docker-compose` commands"""
"""interpret the output of `docker compose` commands"""

import json
import re
Expand All @@ -13,7 +13,7 @@ def parse_docker_compose_up_line(line):
match = try_match(
r'(?P<service>\S+)(?P<delimiter>[_-])\d+\s*\| (?P<payload>.*)\n', line)
if match is not None:
# Some docker-compose setups (versions?) prefix the service name by the
# Some docker compose setups (versions?) prefix the service name by the
# project name, while others don't. The parts of the name are
# delimited by either underscores or hyphens, and we don't use service
# names with either delimiter in them, so we can pull apart the name
Expand All @@ -34,7 +34,7 @@ def parse_docker_compose_up_line(line):
})

# begin_create_container: {container}
begin_create_container = r'(Rec|C)reating (?P<container>\S+)\s*\.\.\.\s*'
begin_create_container = r'\s*(Rec|C)reating (?P<container>\S+)\s*\.\.\.\s*'
match = try_match(begin_create_container, line)
if match is not None:
return ('begin_create_container', {
Expand All @@ -48,26 +48,26 @@ def parse_docker_compose_up_line(line):
'container': match.groupdict()['container']
})

# Different docker-compose setups (versions?) produce different output
# Different docker compose setups (versions?) produce different output
# when a container is creating/created. Here are the other flavors of
# begin_create_container and finish_create_container.

# begin_create_container: {container}
match = try_match(r'Container (?P<container>\S+)\s+Creating\s*', line)
match = try_match(r'\s*Container (?P<container>\S+)\s+Creating\s*', line)
if match is not None:
return ('begin_create_container', {
'container': match.groupdict()['container']
})

# finish_create_container: {container}
match = try_match(r'Container (?P<container>\S+)\s+Created\s*', line)
match = try_match(r'\s*Container (?P<container>\S+)\s+Created\s*', line)
if match is not None:
return ('finish_create_container', {
'container': match.groupdict()['container']
})

# attach_to_logs: {'containers': [container, ...]}
match = try_match(r'Attaching to (?P<containers>\S+(, \S+)*\s*)', line)
match = try_match(r'\s*Attaching to (?P<containers>\S+(, \S+)*\s*)', line)
if match is not None:
return ('attach_to_logs', {
'containers': [
Expand All @@ -77,19 +77,19 @@ def parse_docker_compose_up_line(line):
})

# image_build_success: {image}
match = try_match(r'Successfully built (?P<image>\S+)\s*', line)
match = try_match(r'\s*Successfully built (?P<image>\S+)\s*', line)
if match is not None:
return ('image_build_success', {'image': match.groupdict()['image']})

return ('other', {'payload': line})


def parse_docker_compose_down_line(line):
match = try_match(r'Removing network (?P<network>\S+)\n', line)
match = try_match(r'\s*Removing network (?P<network>\S+)\n', line)
if match is not None:
return ('remove_network', {'network': match.groupdict()['network']})

begin_stop_container = r'Stopping (?P<container>\S+)\s*\.\.\.\s*'
begin_stop_container = r'\s*Stopping (?P<container>\S+)\s*\.\.\.\s*'
match = try_match(begin_stop_container, line)
if match is not None:
return ('begin_stop_container', {
Expand All @@ -102,7 +102,7 @@ def parse_docker_compose_down_line(line):
'container': match.groupdict()['container']
})

begin_remove_container = r'Removing (?P<container>\S+)\s*\.\.\.\s*'
begin_remove_container = r'\s*Removing (?P<container>\S+)\s*\.\.\.\s*'
match = try_match(begin_remove_container, line)
if match is not None:
return ('begin_remove_container', {
Expand Down
Loading