Skip to content

Add missing docker configurations #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ modules.xml
app_test
django_project
manage.py
Dockerfile
start.sh
wait-for-it.sh
test*xml
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.10-slim-buster

ENV PYTHONUNBUFFERED=1

RUN apt-get update && \
apt-get install -y git

WORKDIR /app
COPY ./setup.* ./README.md ./pyproject.toml ./

RUN pip install --upgrade pip && \
pip install poetry && \
poetry export -f requirements.txt -o requirements.txt --with dev && \
pip uninstall --yes poetry && \
pip install --no-cache-dir --upgrade --upgrade-strategy=eager -r requirements.txt

COPY . .

ENV PIPENV_IGNORE_VIRTUALENVS=1
# keep the container running
CMD ["tail", "-f", "/dev/null"]
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: lint test_activemq test_rabbitmq tests check

_down:
docker compose down --remove-orphans # prevent port binding conflict

lint: _down
docker compose up --detach lint-formatter
docker compose exec --interactive lint-formatter ./scripts/start-formatter-lint.sh
$(MAKE) _down

test_activemq: _down
docker compose up --detach integration-tests-active-mq
docker compose exec --interactive integration-tests-active-mq ./scripts/start-tests.sh
$(MAKE) _down

test_rabbitmq: _down
docker compose up --detach integration-tests-rabbit-mq
docker compose exec --interactive integration-tests-rabbit-mq ./scripts/start-tests.sh
$(MAKE) _down

test: test_activemq test_rabbitmq

check: lint test
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ defined, this parameter **must** be an integer!

## Tests

### In a docker container (without installing dependencies locally)

Execute tests for both ActiveMQ and RabbitMQ

```bash
make test
```

### With python dependencies installed locally

In order to execute tests for ActiveMQ, execute the following:
```bash
docker-compose up -d broker-activemq
Expand Down
18 changes: 1 addition & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ services:
build: .
volumes:
- .:/app
command: [ "./scripts/start-formatter-lint.sh" ]
networks:
- djangostompnetwork

integration-tests:
integration-tests-rabbit-mq:
build: .
volumes:
- .:/app
depends_on:
broker-rabbitmq:
condition: service_healthy
command: ["./scripts/start-tests.sh"]
environment:
STOMP_SERVER_HOST: "broker-rabbitmq"
STOMP_SERVER_PORT: 61613
Expand All @@ -28,27 +26,13 @@ services:
- .:/app
depends_on:
- broker-activemq
command: ["./scripts/start-tests.sh"]
environment:
STOMP_SERVER_HOST: "broker-activemq"
STOMP_SERVER_PORT: 61613
STOMP_SERVER_GUI_PORT: 8161
networks:
- djangostompnetwork

integration-tests-tox:
build:
context: .
dockerfile: Dockerfile.tox-tests
volumes:
- .:/app
depends_on:
broker-rabbitmq:
condition: service_healthy
command: ["./scripts/start-tox-tests.sh"]
networks:
- djangostompnetwork

broker-activemq:
image: rmohr/activemq:latest
ports:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid

import pytest
from django.conf import settings
from django.core.management import call_command

from django_stomp.builder import build_publisher
Expand All @@ -20,7 +21,7 @@ def _to_publish_to_source_broker():
publisher.send(sample_body, fake_source, headers)

def _to_move_the_message_and_evaluate_result():
fake_custom_broker_host = "localhost"
fake_custom_broker_host = settings.STOMP_SERVER_HOST
fake_custom_broker_port = "61614"

call_command("move_messages", fake_source, fake_target, fake_custom_broker_host, fake_custom_broker_port)
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_execution/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pytest
import trio
from django.conf import settings as django_settings
from django.db.backends.signals import connection_created
from pytest_mock import MockFixture
from stomp.exception import NotConnectedException
Expand Down Expand Up @@ -188,7 +189,7 @@ def test_should_create_durable_subscriber_and_receive_standby_messages(mocker: M
assert destination_status.messages_enqueued == 3
assert destination_status.messages_dequeued == 3

all_offline_subscribers = list(offline_durable_subscribers("localhost"))
all_offline_subscribers = list(offline_durable_subscribers(settings.STOMP_SERVER_HOST))
assert len(all_offline_subscribers) > 0
for index, subscriber_setup in enumerate(all_offline_subscribers):
if subscriber_setup.subscriber_id == f"{temp_uuid_listener}-listener":
Expand Down Expand Up @@ -688,10 +689,9 @@ def test_should_use_heartbeat_and_dont_lose_connection_when_using_background_pro
assert any(sending_ack_frame_regex.match(m) for m in caplog.messages)
assert not any(heartbeat_timeout_regex.match(m) for m in caplog.messages)


@pytest.mark.skipif(is_testing_against_rabbitmq(), reason="RabbitMQ doesn't holds the concept of a durable subscriber")
def test_shouldnt_create_a_durable_subscriber_when_dealing_with_virtual_topics():
all_offline_subscribers_before_the_virtual_topic_connection = list(offline_durable_subscribers("localhost"))
all_offline_subscribers_before_the_virtual_topic_connection = list(offline_durable_subscribers(django_settings.STOMP_SERVER_HOST))
destination_two = f"/queue/testing-for-durable-subscriber-with-virtual-topics-{uuid4()}"

some_virtual_topic = f"VirtualTopic.{uuid.uuid4()}"
Expand All @@ -700,7 +700,7 @@ def test_shouldnt_create_a_durable_subscriber_when_dealing_with_virtual_topics()
virtual_topic_consumer_queue, callback_move_and_ack_path, param_to_callback=destination_two, is_testing=True
)

all_offline_subscribers_after_the_virtual_topic_connection = list(offline_durable_subscribers("localhost"))
all_offline_subscribers_after_the_virtual_topic_connection = list(offline_durable_subscribers(django_settings.STOMP_SERVER_HOST))

assert sorted(all_offline_subscribers_before_the_virtual_topic_connection) == sorted(
all_offline_subscribers_after_the_virtual_topic_connection
Expand Down
3 changes: 2 additions & 1 deletion tests/support/activemq/connections_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from typing import Generator

import requests
from django.conf import settings
from parsel import Selector

from django_stomp.helpers import eval_str_as_boolean
from tests.support.dtos import ConsumerStatus


def consumers_details(connection_id, host="localhost") -> Generator[ConsumerStatus, None, None]:
def consumers_details(connection_id, host=settings.STOMP_SERVER_HOST) -> Generator[ConsumerStatus, None, None]:
sleep(1)

params = {"connectionID": connection_id}
Expand Down
3 changes: 2 additions & 1 deletion tests/support/activemq/message_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from time import sleep

import requests
from django.conf import settings
from parsel import Selector

from tests.support.dtos import MessageStatus


def retrieve_message_published(destination_name, host="localhost") -> MessageStatus:
def retrieve_message_published(destination_name, host=settings.STOMP_SERVER_HOST) -> MessageStatus:
sleep(1)
address = f"http://{host}:8161/admin/browse.jsp?JMSDestination={destination_name}"
result = requests.get(address, auth=("admin", "admin"))
Expand Down
3 changes: 2 additions & 1 deletion tests/support/activemq/queue_details.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from time import sleep

import requests
from django.conf import settings
from parsel import Selector

from tests.support.dtos import CurrentDestinationStatus


def current_queue_configuration(queue_name, host="localhost") -> CurrentDestinationStatus:
def current_queue_configuration(queue_name, host=settings.STOMP_SERVER_HOST) -> CurrentDestinationStatus:
sleep(1)
result = requests.get(f"http://{host}:8161/admin/queues.jsp", auth=("admin", "admin"))
selector = Selector(text=str(result.content))
Expand Down
3 changes: 2 additions & 1 deletion tests/support/activemq/topic_details.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from time import sleep

import requests
from django.conf import settings
from parsel import Selector

from tests.support.dtos import CurrentDestinationStatus


def current_topic_configuration(topic_name, host="localhost") -> CurrentDestinationStatus:
def current_topic_configuration(topic_name, host=settings.STOMP_SERVER_HOST) -> CurrentDestinationStatus:
sleep(1)
result = requests.get(f"http://{host}:8161/admin/topics.jsp", auth=("admin", "admin"))
selector = Selector(text=str(result.content))
Expand Down
2 changes: 1 addition & 1 deletion tests/support/dtos.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MessageStatus:
properties: Optional[Dict]


@dataclass(frozen=True)
@dataclass(frozen=True, order=True)
class SubscriberSetup:
address_to_subscriber_details: str
subscriber_id: str
Expand Down
11 changes: 6 additions & 5 deletions tests/support/rabbitmq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Optional

import requests
from django.conf import settings
from requests.adapters import HTTPAdapter

from tests.support.dtos import ConsumerStatus
Expand All @@ -23,7 +24,7 @@
_overview_request_path = "/api/overview"


def current_queue_configuration(queue_name, host="localhost", port=15672) -> Optional[CurrentDestinationStatus]:
def current_queue_configuration(queue_name, host=settings.STOMP_SERVER_HOST, port=15672) -> Optional[CurrentDestinationStatus]:
result = _do_request(host, port, _specific_queue_details_request_path.format(queue_name=queue_name))

logger.debug("RabbitMQ request result: %s", result)
Expand Down Expand Up @@ -51,7 +52,7 @@ def current_queue_configuration(queue_name, host="localhost", port=15672) -> Opt
)


def current_topic_configuration(topic_name, host="localhost", port=15672) -> Optional[CurrentDestinationStatus]:
def current_topic_configuration(topic_name, host=settings.STOMP_SERVER_HOST, port=15672) -> Optional[CurrentDestinationStatus]:
queues = _do_request(host, port, _queues_details_request_path + "?name=&use_regex=false")
for queue_details in queues:
queue_name = queue_details["name"]
Expand All @@ -69,7 +70,7 @@ def current_topic_configuration(topic_name, host="localhost", port=15672) -> Opt
return None


def consumers_details(connection_id, host="localhost", port=15672) -> Generator[ConsumerStatus, None, None]:
def consumers_details(connection_id, host=settings.STOMP_SERVER_HOST, port=15672) -> Generator[ConsumerStatus, None, None]:
channels = _do_request(host, port, _channels_details_request_path)
for channel in channels:
channel_name = channel["connection_details"]["name"]
Expand Down Expand Up @@ -98,7 +99,7 @@ def consumers_details(connection_id, host="localhost", port=15672) -> Generator[
)


def retrieve_message_published(destination_name, host="localhost", port=15672) -> MessageStatus:
def retrieve_message_published(destination_name, host=settings.STOMP_SERVER_HOST, port=15672) -> MessageStatus:
body = json.dumps(
{
"vhost": "/",
Expand All @@ -123,7 +124,7 @@ def retrieve_message_published(destination_name, host="localhost", port=15672) -
return MessageStatus(None, details, persistent, correlation_id, {**headers, **properties})


def get_broker_version(host="localhost", port=15672) -> str:
def get_broker_version(host=settings.STOMP_SERVER_HOST, port=15672) -> str:
broker_overview = _do_request(host, port, _overview_request_path)
return broker_overview["rabbitmq_version"]

Expand Down
Loading