Skip to content

Test framework

Alan B. Christie edited this page Aug 15, 2025 · 9 revisions

The engine is "Event Driven", so to test it we simply have to send events (Protocol Buffer messages) to its handle_message() method.

This sounds simple enough but a key element of the engine is the manipulation of database records, and the asynchronous launching of Jobs. As a result, under test, the engine needs to run in a multi-process world as the DM does using a "mock" message bus to allow the transmission of and reception of messages. The engine relies on the behaviour of an InstanceLauncher and Workflow API Adapter in order to progress through the numerous stats a running workflow experiences. All of this leads to a test framework that is a challenging environment to construct, resulting in a significant amount of code before even the simplest of tests can be executed.

The test framework is based on the operation of the following test modules: -

  1. A unit test InstanceLauncher. A class able to simulate the execution of DM Jobs.
  2. A unit test WorkflowAPIAdapter. A class able to simulate the expected DM database tables.
  3. A unit test MessageDispatcher. A class that is used by the instance launcher to simulate the transmission of protocol buffer messages.
  4. A unit test MessageQueue. A class that is used by the message dispatcher to simulate the existence of the DM's RabbitMQ bus.

Their implementations can be found in the repository's tests directory: -

  • tests/instance_launcher.py
  • tests/wapi_adapter.py
  • tests/message_dispatcher.py
  • tests/message_queue.py

Each of these test modules has its own unit test module, which verifies the simulated behaviour is as expected: -

  • tests/test_test_instance_launcher.py
  • tests/test_test_wapi_adpater.py
  • tests/test_test_message_dispatcher.py
  • tests/test_test_message_queue.py

All of the above are required to simulate the services that are offered by the DM. They are essential if the engine's behaviour is to be thoroughly tested.

A brief tour of the test framework follows, helped by a simple diagram: -

https://github.com/user-attachments/assets/ec45304c-c65b-4ca8-8e57-c97ee1934b25

See also

  1. The "Unit testing the WorkflowEngine" section of the Shortcut doc Workflow engine design
Clone this wiki locally