Skip to content

Unit Test server and interface

John R. D'Orazio edited this page Jun 12, 2024 · 7 revisions

Frontend

The Unit Test frontend can be found at https://litcal-tests.johnromanodorazio.com. This interface has a repository of it's own, the source code is at Liturgical-Calendar/UnitTestInterface.

The frontend will automatically pick up on unit tests that are created in the LiturgicalCalendar API backend, through the discovery endpoint https://litcal.johnromanodorazio.com/api/${version}/tests/ . Here ${version} can have a value of dev for the latest cutting edge updates to the LitCal API, or a fixed version such as v4 (not yet released) for the latest stable api endpoint. The LitCalTestsIndex.php endpoint is curated in the Liturgical-Calendar/LiturgicalCalendarAPI repository.

It communicates with the Unit Test backend via websockets, sending requests for tests to be run, gathering the results and updating the UI based on those results.

Discovery endpoint

The /tests/ discovery endpoint will pick up all Unit Tests defined in the tests folder within the Liturgical-Calendar/LiturgicalCalendarAPI repository (https://github.com/Liturgical-Calendar/LiturgicalCalendarAPI/tree/development/tests) and serve a response in JSON format that is readable by the frontend. This endpoint uses the LitCal\TestsIndex class to gather information about the available tests.

Backend

The Unit Test backend is a websocket server listening at https://litcal-test.johnromanodorazio.com.

Websocket server

The backend websocket server is created in the PHP script LitCalTestServer.php which is also curated in the LiturgicalCalendarAPI repository alongside the API itself.

The PHP websocket server is run as a system service defined in /etc/systemd/system/litcal-tests.service as follows:

[Unit]
Description=LitCal Unit tests service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
User=**********
Group=*********
WorkingDirectory=/**********/api/dev/
Restart=always
RestartSec=1
ExecStart=/usr/bin/env php8.1 /**********/api/dev/LitCalTestServer.php

[Install]
WantedBy=multi-user.target

Note: cannot update to php8.2 or php8.3 until ratchetphp/Ratchet issue #1003 is fixed...

LitCal\Health class

The websocket server LitCalTestServer.php depends on the LitCal\Health class which is also curated in the LiturgicalCalendarAPI repository (src\Health.php)

The LitCal\Health class can run unit tests requested by the frontend through websocket messaging, as it has backend knowledge of the available tests in the same way that the /tests/ endpoint gathers the same information for the frontend.

The LitCal\Health class can be considered the orchestrator, assisting the backend end websocket server in running specific tests requested by the frontend and formulating a response with the test results in JSON format.

Clone this wiki locally