Skip to content

Commit 6877080

Browse files
committed
integration test
1 parent e5f78ad commit 6877080

File tree

1 file changed

+91
-13
lines changed

1 file changed

+91
-13
lines changed

.github/workflows/test-metatrader5-integration.yml

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ jobs:
3131
Start-Process -FilePath .\mt5setup.exe -ArgumentList "/auto" -Wait
3232
# Give installation some time to complete
3333
Start-Sleep -Seconds 60
34+
35+
- name: Create MetaTrader configuration
36+
run: |
37+
# Create directory for MetaTrader configuration
38+
$mt5ConfigDir = "C:\Users\runneradmin\AppData\Roaming\MetaQuotes\Terminal"
39+
if (!(Test-Path $mt5ConfigDir)) {
40+
New-Item -Path $mt5ConfigDir -ItemType Directory -Force
41+
Write-Host "Created MetaTrader configuration directory: $mt5ConfigDir"
42+
}
3443
3544
- name: Verify MetaTrader 5 Installation and Start Terminal
3645
run: |
@@ -45,29 +54,98 @@ jobs:
4554
Write-Host "Listing MetaTrader 5 installation directory:"
4655
Get-ChildItem "C:\Program Files\MetaTrader 5"
4756
48-
# Start MT5 terminal and give it time to initialize
49-
Start-Process -FilePath $mtPath -ArgumentList "/portable" -PassThru
50-
Write-Host "Started MetaTrader 5 terminal"
51-
Start-Sleep -Seconds 30
57+
# Start MT5 terminal without UI and give it time to initialize
58+
# Use /portable mode to avoid login requirements
59+
$process = Start-Process -FilePath $mtPath -ArgumentList "/portable", "/skipupdate" -PassThru -WindowStyle Hidden
60+
$pid = $process.Id
61+
Write-Host "Started MetaTrader 5 terminal with PID: $pid"
62+
63+
# Give more time for initialization
64+
Write-Host "Waiting 60 seconds for MetaTrader 5 to initialize..."
65+
Start-Sleep -Seconds 60
5266
53-
# Verify MT5 process is running
54-
$process = Get-Process "terminal64" -ErrorAction SilentlyContinue
55-
if ($process) {
56-
Write-Host "MetaTrader 5 terminal is running with PID: $($process.Id)"
57-
} else {
58-
Write-Error "MetaTrader 5 terminal is not running."
67+
# Verify MT5 process is still running
68+
try {
69+
$runningProcess = Get-Process -Id $pid -ErrorAction Stop
70+
Write-Host "MetaTrader 5 terminal is still running with PID: $pid"
71+
} catch {
72+
Write-Error "MetaTrader 5 terminal is no longer running. It may have crashed."
73+
exit 1
5974
}
6075
6176
- name: Install Python dependencies
6277
run: |
6378
python -m pip install --upgrade pip
6479
pip install MetaTrader5
6580
66-
- name: Test MetaTrader5 connection
81+
- name: Debug MetaTrader environment
82+
run: |
83+
# Check running processes
84+
Write-Host "Checking for MetaTrader processes:"
85+
Get-Process | Where-Object { $_.Name -like "*terminal*" -or $_.Name -like "*meta*" } | Format-Table Id, Name, Path, StartTime
86+
87+
# Check MT5 installation directories
88+
Write-Host "Checking MetaTrader installation directories:"
89+
if (Test-Path "C:\Program Files\MetaTrader 5") {
90+
Get-ChildItem "C:\Program Files\MetaTrader 5" -Recurse | Select-Object -First 30 | Format-Table FullName
91+
}
92+
93+
# Check for MetaQuotes directories in AppData
94+
Write-Host "Checking AppData for MetaQuotes directories:"
95+
if (Test-Path "C:\Users\runneradmin\AppData\Roaming\MetaQuotes") {
96+
Get-ChildItem "C:\Users\runneradmin\AppData\Roaming\MetaQuotes" -Recurse | Select-Object -First 30 | Format-Table FullName
97+
}
98+
99+
- name: Test MetaTrader5 connection with retry
67100
run: |
68101
# Print environment information
69102
Write-Host "Environment variables:"
70103
Get-ChildItem Env: | Format-Table -AutoSize
71104
72-
# Run the test with diagnostic info
73-
python tests/integration/test_mt5_connection.py
105+
# Create a retry script for connection
106+
$script = @"
107+
import MetaTrader5 as mt5
108+
import time
109+
import sys
110+
111+
print(f"MetaTrader5 package version: {mt5.__version__}")
112+
113+
# Try to connect with retries
114+
max_attempts = 5
115+
for attempt in range(max_attempts):
116+
print(f"Connection attempt {attempt+1}/{max_attempts}...")
117+
118+
# Initialize MT5 connection
119+
if mt5.initialize():
120+
print("MetaTrader5 initialized successfully")
121+
# Get terminal info
122+
terminal_info = mt5.terminal_info()
123+
if terminal_info is not None:
124+
print(f"Terminal info: connected={terminal_info.connected}, community_account={terminal_info.community_account}")
125+
else:
126+
print("Failed to get terminal info")
127+
128+
# Get account info
129+
account_info = mt5.account_info()
130+
if account_info is not None:
131+
print(f"Account info: server={account_info.server}, balance={account_info.balance}")
132+
else:
133+
print("Failed to get account info - this is normal without login credentials")
134+
135+
mt5.shutdown()
136+
sys.exit(0)
137+
else:
138+
error = mt5.last_error()
139+
print(f"initialize() failed, error code = {error}")
140+
# Wait before retrying
141+
time.sleep(10)
142+
143+
# If we got here, all attempts failed
144+
sys.exit(1)
145+
"@
146+
147+
# Save the script to a file
148+
$script | Out-File -FilePath "retry_connection.py" -Encoding utf8
149+
150+
# Run the script
151+
python retry_connection.py

0 commit comments

Comments
 (0)