Bridge Validation Tests
Relevant source files
The following files were used as context for generating this wiki page:
Bridge Validation Tests represent a critical quality assurance layer in the mt5-docker project, ensuring that the gRPC bridge accurately replicates the official MetaTrader 5 (MT5) Python API. The suite validates function signatures, constant completeness, and service resilience within the Wine-based container environment.
Sources: tests/test_bridge_validation.py:1-12, README.md
Architecture and Integration
The bridge facilitates communication between a Linux host and the MetaTrader 5 terminal running under Wine. Validation tests ensure that the gRPC service defined in mt5.proto and implemented in bridge.py correctly maps to the expected MT5 functions.
This diagram illustrates the flow of a validation request from the test suite to the MT5 terminal via the gRPC bridge.
Sources: docker/container/metatrader/mt5.proto, tests/test_bridge_validation.py:284-290
Signature Validation
The test suite contains a comprehensive mapping of official MT5 Python API functions. These are compared against the bridge implementation to ensure parameter parity and return type consistency.
Connection and Information Functions
The suite verifies that core connection functions like initialize and login accept all standard parameters including path, login, password, server, and timeout.
| Function | Parameters | Returns |
|---|---|---|
initialize | path, login, password, server, timeout, portable | bool |
login | login, password, server, timeout | bool |
version | - | tuple | None |
terminal_info | - | TerminalInfo | None |
Sources: tests/test_bridge_validation.py:41-75
Bridge-Specific Health and Constants
Beyond official MT5 parity, the bridge introduces specific methods for container health and metadata synchronization.
- HealthCheck: Returns a
HealthStatuscontaininghealthyandmt5_availableflags. - GetConstants: Retrieves a map of all MT5 enumerations to ensure the remote client has access to the correct integer values for timeframes and order types.
Sources: tests/test_bridge_validation.py:298-312, docker/container/metatrader/mt5.proto:217-218
Constants Completeness
The validation suite ensures that the bridge provides all 21 timeframe constants, 9 order types, and 6 trade actions defined in the MT5 ecosystem.
Service Recovery and Failure Simulation
Tests simulate real-world failure scenarios to ensure the bridge and its supervisor (s6-overlay) handle disruptions gracefully.
Recovery Mechanisms
- Reconnection Handling: Tests verify that the bridge survives rapid connect/disconnect cycles from gRPC clients.
- Restart Markers: The suite validates the existence of the
RESTART_TOKENmechanism, which allows the health monitor to signal for a service restart vias6-svstat. - Fault Tolerance: The bridge must handle invalid symbol requests or empty position lists without crashing, returning empty responses instead of raising exceptions.
Sources: tests/test_bridge_validation.py:382-410, tests/test_static.py:461-470, tests/constants.py:228-229
Health Monitoring Process
The health monitor runs as a background process within the container, checking the bridge status at defined intervals.
Environment Validation
Static tests verify the consistency of the environment before runtime tests are executed. This includes checking that the versions.env file correctly pins critical dependencies.
| Dependency | Required Prefix | Purpose |
|---|---|---|
PYTHON_VERSION | 3.12 | Wine compatibility / MT5 requirement |
NUMPY_VERSION | 1.26 | Wine/MT5 compatibility |
GRPCIO_VERSION | 1.76 | Bridge communication |
PROTOBUF_VERSION | 6.31.1 | gRPC gencode parity |
Sources: tests/test_static.py:68-117, docker/container/metatrader/setup.sh:137-142
Conclusion
The Bridge Validation Tests serve as the primary safeguard for the gRPC communication layer. By strictly enforcing API parity with the official MetaTrader 5 Python module and validating the robustness of the containerized environment, this suite ensures that algorithmic trading strategies can operate reliably across the bridge.