Skip to content

Commit b0a5da3

Browse files
author
Alan Christie
committed
docs: Doc tweak
1 parent 1c1795b commit b0a5da3

12 files changed

+68
-37
lines changed

tests/api_adapter.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""The UnitTest API Adapter.
2+
3+
This 'simulates' the sort of responses you can expect from the DM API/Model.
4+
It stimulates a Database by using dictionaries that are pickled to (and unpickled from)
5+
the file system after acquiring a lock object. Pickling is required to
6+
(because it's a simple built-in mechanism in Python) to persist data
7+
between processes in the multi-processing framework we run in because we ultimately need
8+
to simulate the multi-pod messaging-based framework of the DM.
9+
10+
A separate pickle file is used for each 'simulated' model table and the object
11+
initialiser resets all the pickle files (located in 'tests/pickle-files').
12+
13+
Job definitions are loaded (statically) from the content of the
14+
'tests/job-definitions/job-definitions.yaml' file and yielded through the 'get_job()'
15+
method.
16+
"""
17+
118
import os
219
from multiprocessing import Lock
320
from pickle import Pickler, Unpickler

tests/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""An emulation of the Data Manager config module.
2-
A location of common constants."""
2+
A module of common constants."""
33

44
# The project ID used in the tests (there is only one atm)
55
TEST_PROJECT_ID: str = "project-00000000-0000-0000-0000-000000000001"

tests/instance_launcher.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""The UnitTest Instance Launcher.
2+
3+
It runs Python module modules defined in the unit-test job-definitions file.
4+
5+
It also uses the UnitTestMessageDispatcher to send a simulated
6+
'end of instance' PodMessage that are normally sent to the WorkflowEngine's
7+
'handle_message()' method by the underlying queue. The 'exit code' of the module is
8+
passed to the WorkflowEngine through the PodMessage - so if the module fails
9+
(i.e. returns a non-zero exit code) then the WorkflowEngine will see that the PodMessage.
10+
This allows you to write jobs that fail and see how the WorkflowEngine responds.
11+
12+
Instances (jobs) are executed in a simulated project directory - actually
13+
tests/project-root/project-00000000-0000-0000-0000-000000000001. The project directory
14+
is created by the UnitTestInstanceLauncher and is also wiped as the launcher initialises
15+
(so the start of each test begins with an empty project directory).
16+
"""
17+
118
import json
219
import os
320
import shutil
@@ -28,22 +45,7 @@ def project_file_exists(file_name: str) -> bool:
2845

2946

3047
class UnitTestInstanceLauncher(InstanceLauncher):
31-
"""A unit test instance launcher, which runs the
32-
Python module that matches the job name in the provided specification.
33-
34-
The Python module used to satisfy the step matches the job name in the
35-
step specification. If the step_specification's 'job' is 'my_job', then the launcher
36-
will run the Python module 'my_job.py' in the 'jobs' directory. The
37-
module is run synchronously - i.e. the launch() method waits for the
38-
module to complete.
39-
40-
It then uses the UnitTestMessageDispatcher to send a simulated
41-
'end of instance' PodMessage that will be received by the WorkflowEngine's
42-
'handle_message()' method. The 'exit code' of the module is passed to the
43-
WorkflowEngine through the PodMessage - so if the module fails (i.e. returns
44-
a non-zero exit code) then the WorkflowEngine will see that the PodMessage.
45-
This allows you to write jobs that fail and see how the WorkflowEngine responds.
46-
"""
48+
"""A unit test instance launcher."""
4749

4850
def __init__(
4951
self, api_adapter: UnitTestAPIAdapter, msg_dispatcher: UnitTestMessageDispatcher

tests/message_dispatcher.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""The UnitTest Message Dispatcher.
2+
3+
A very simple object that relies on an underlying message queue.
4+
Here we offer a minimal implementation that simply sends a (protocol buffer) message
5+
to the queue.
6+
"""
7+
18
from google.protobuf.message import Message
29

310
from tests.message_queue import UnitTestMessageQueue

tests/message_queue.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
"""The UnitTest Message Queue.
2+
3+
A simulation of the RabbitMQ queue in the DM. It has a 'put()' method that
4+
serializes ProtocolBuffer messages and places them on a queue. The 'run()' method
5+
picks messages off the queue and deserializes them back into ProtocolBuffer objects
6+
before sending them to a receiver function.
7+
8+
In the UnitTest framework the receiver is the WorkflowEngine's 'handle_message()'
9+
function.
10+
11+
The queue needs to be started (before any testing) and stopped (after testing).
12+
This is typically done by the pytest 'basic engine' fixture in
13+
'test_workflow_engine_examples.py'.
14+
"""
15+
116
from contextlib import suppress
217
from multiprocessing import Event, Process, Queue
318
from queue import Empty

tests/test_decoder_minimal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Tests for the decoder package.
21
import os
32
from typing import Any, Dict
43

tests/test_test_api_adapter.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Tests for the decoder package.
2-
31
import pytest
42

53
pytestmark = pytest.mark.unit

tests/test_test_instance_launcher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Tests for the decoder package.
21
import json
32

43
import pytest

tests/test_test_message_dispatcher.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Tests for the decoder package.
2-
31
from datetime import datetime, timezone
42

53
import pytest
@@ -15,10 +13,16 @@
1513
@pytest.fixture
1614
def basic_dispatcher():
1715
utmq = UnitTestMessageQueue()
18-
return UnitTestMessageDispatcher(msg_queue=utmq)
16+
utmd = UnitTestMessageDispatcher(msg_queue=utmq)
17+
utmq.start()
18+
19+
yield utmd
20+
21+
utmq.stop()
22+
utmq.join()
1923

2024

21-
def test_get_nop_job(basic_dispatcher):
25+
def test_send_start(basic_dispatcher):
2226
# Arrange
2327
msg = WorkflowMessage()
2428
msg.timestamp = f"{datetime.now(timezone.utc).isoformat()}Z"

tests/test_test_message_queue.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@ def basic_queue():
2424
receiver = Receiver()
2525
utmq = UnitTestMessageQueue(receiver=receiver.handle_msg)
2626
utmq.start()
27+
2728
yield utmq
29+
2830
utmq.stop()
2931
utmq.join()
3032

3133

32-
def test_start_and_stop(basic_queue):
33-
# Arrange
34-
35-
# Act
36-
pass
37-
38-
# Assert
39-
40-
4134
def test_send_messages(basic_queue):
4235
# Arrange
4336

0 commit comments

Comments
 (0)