Skip to content

Commit 872a417

Browse files
committed
test again
1 parent 9dec16b commit 872a417

File tree

1 file changed

+108
-63
lines changed

1 file changed

+108
-63
lines changed

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

Lines changed: 108 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -55,109 +55,154 @@ jobs:
5555
Write-Host "Found MT5 at: $path"
5656
}
5757
58-
exit 1
59-
}
60-
61-
- name: Install Python dependencies
58+
exit 1details about system architecture
59+
} $architecture = [System.Environment]::Is64BitOperatingSystem ? "64-bit" : "32-bit"
60+
Write-Host "System Architecture: $architecture"
61+
- name: Install Python dependenciesecture: $([IntPtr]::Size * 8)-bit"
6262
run: |
6363
python -m pip install --upgrade pip
6464
pip install MetaTrader5 pytest
6565
6666
- name: Configure MT5 for headless operation
6767
run: |
6868
# Create data directory for portable mode
69-
$mt5DataDir = ".\MT5_Data"
69+
$mt5DataDir = ".\MT5_Data"test
7070
New-Item -Path $mt5DataDir -ItemType Directory -Force
71-
71+
me: Configure MT5 for headless operation
7272
# Set environment variables for headless operation
7373
echo "MT5_HEADLESS=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7474
echo "MT5_TIMEOUT=60000" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7575
echo "MT5_DEBUG=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7676
7777
# Find MT5 path to pass to the test - check both 32-bit and 64-bit versions
78-
$mt5Path = ""
79-
$possiblePaths = @(
80-
"C:\Program Files\MetaTrader 5\terminal64.exe",
78+
$mt5Path = ""DLESS=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
79+
$possiblePaths = @(0000" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
80+
"C:\Program Files\MetaTrader 5\terminal64.exe",UB_ENV -Encoding utf8 -Append
8181
"C:\Program Files\MetaTrader 5\terminal.exe",
82-
".\MetaTrader 5\terminal64.exe",
82+
".\MetaTrader 5\terminal64.exe",t - check both 32-bit and 64-bit versions
8383
".\MetaTrader 5\terminal.exe",
8484
"$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal64.exe",
8585
"$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal.exe"
86-
)
87-
86+
) "C:\Program Files\MetaTrader 5\terminal.exe",
87+
".\MetaTrader 5\terminal64.exe",
8888
foreach ($path in $possiblePaths) {
89-
if (Test-Path $path) {
90-
$mt5Path = $path
89+
if (Test-Path $path) {es\Terminal\MetaTrader5\terminal64.exe",
90+
$mt5Path = $pathQuotes\Terminal\MetaTrader5\terminal.exe"
9191
$mt5Dir = Split-Path -Parent $mt5Path
9292
echo "MT5_PATH=$mt5Path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
9393
echo "MT5_DIR=$mt5Dir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
9494
Write-Host "Setting MT5_PATH to $mt5Path"
9595
Write-Host "Setting MT5_DIR to $mt5Dir"
96-
97-
# Create minimal configuration file to help with headless mode
98-
$configLines = @(
99-
'[Common]',
100-
'Login=0',
96+
$mt5Dir = Split-Path -Parent $mt5Path
97+
# Create minimal configuration file to help with headless mode-Encoding utf8 -Append
98+
$configLines = @(5Dir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
99+
'[Common]',etting MT5_PATH to $mt5Path"
100+
'Login=0',Setting MT5_DIR to $mt5Dir"
101101
'ProxyEnable=0',
102-
'CertCheckDisable=1',
102+
'CertCheckDisable=1',uration file to help with headless mode
103103
'AutoUpdate=0',
104104
'DisableStartupCompany=1',
105105
'EnableOpenCL=0',
106-
'News=0',
107-
'StartupCompany=0',
108-
'Community=0',
109-
'AutoUpdate.Enable=0'
110-
)
106+
'News=0',ble=0',
107+
'StartupCompany=0',',
108+
'Community=0',,
109+
'AutoUpdate.Enable=0'y=1',
110+
) 'EnableOpenCL=0',
111111
$configPath = Join-Path $mt5Dir "config\default.ini"
112112
New-Item -Path (Split-Path -Parent $configPath) -ItemType Directory -Force
113113
$configLines | Out-File -FilePath $configPath -Encoding utf8
114114
Write-Host "Created default config at $configPath"
115-
116-
break
117-
}
115+
)
116+
breakigPath = Join-Path $mt5Dir "config\default.ini"
117+
} New-Item -Path (Split-Path -Parent $configPath) -ItemType Directory -Force
118+
} $configLines | Out-File -FilePath $configPath -Encoding utf8
119+
Write-Host "Created default config at $configPath"
120+
- name: Configure system for MT5 communication
121+
run: |break
122+
# Create registry settings that can help with IPC communication
123+
Write-Host "Configuring system registry for MT5 communication"
124+
125+
# Ensure the MetaTrader registry key exists
126+
$registryPath = "HKCU:\Software\MetaQuotes"
127+
if (-not (Test-Path $registryPath)) {
128+
New-Item -Path $registryPath -Force | Out-Nullet-ChildItem Env:
118129
}
119-
130+
ents:"
131+
# Configure Terminal settings if needed
132+
$terminalPath = "$registryPath\Terminal" Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullName
133+
if (-not (Test-Path $terminalPath)) {
134+
New-Item -Path $terminalPath -Force | Out-Null
135+
}
136+
oSize
137+
# Set some registry values that may help with IPC
138+
Set-ItemProperty -Path $terminalPath -Name "HeadlessMode" -Value 1 -Type DWORD -Force
139+
Set-ItemProperty -Path $terminalPath -Name "AllowDllImport" -Value 1 -Type DWORD -Force: |
140+
# Kill any existing MT5 processes
141+
# Check if Python DLLs are accessible from the MT5 installationke "*MetaTrader*" -or $_.Name -like "*terminal*" } | ForEach-Object {
142+
$pythonDllPath = Join-Path (Split-Path -Parent (Get-Command python).Path) "python311.dll"process $($_.Name) with ID $($_.Id)"
143+
if (Test-Path $pythonDllPath) { Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
144+
Write-Host "Python DLL found at: $pythonDllPath"
145+
# Copy Python DLL to MT5 directory to help with IPC
146+
if (Test-Path $env:MT5_DIR) {
147+
Copy-Item -Path $pythonDllPath -Destination $env:MT5_DIR -ForceStart-Sleep -Seconds 5
148+
Write-Host "Copied Python DLL to MT5 directory"
149+
}rst with configurations that help in headless mode
150+
} else {$mt5Process = Start-Process -FilePath $env:MT5_PATH -ArgumentList "/portable", "/config:default.ini", "/skipupdate", "/minimize" -PassThru
151+
Write-Host "Python DLL not found at expected location"with ID $($mt5Process.Id)"
152+
}
153+
fully initialize before Python tries to connect
120154
- name: Debug environment
121155
run: |
122156
Write-Host "Environment variables:"
123-
Get-ChildItem Env:
124-
125-
Write-Host "MT5 directory contents:"
157+
Get-ChildItem Env:mt5Running = Get-Process -Id $mt5Process.Id -ErrorAction SilentlyContinue
158+
if ($mt5Running) {
159+
Write-Host "MT5 directory contents:"till running with ID $($mt5Process.Id)"
126160
if (Test-Path $env:MT5_DIR) {
127-
Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullName
161+
Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullNameWrite-Host "Warning: MT5 process is no longer running"
128162
}
129163
130-
Write-Host "System processes:"
131-
Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | Format-Table -AutoSize
164+
Write-Host "System processes:"isting test script
132165
133-
- name: Test MT5 initialization
134-
run: |
135-
# Kill any existing MT5 processes
136-
Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | ForEach-Object {
137-
Write-Host "Killing process $($_.Name) with ID $($_.Id)"
138-
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
139-
}
140-
141-
# Give system time to clean up processes
142-
Start-Sleep -Seconds 5
143-
144-
# Start MT5 manually first with configurations that help in headless mode
145-
$mt5Process = Start-Process -FilePath $env:MT5_PATH -ArgumentList "/portable", "/config:default.ini", "/skipupdate", "/minimize" -PassThru
146-
Write-Host "Started MT5 process with ID $($mt5Process.Id)"
147-
148-
# Give MT5 time to fully initialize before Python tries to connect
149-
Start-Sleep -Seconds 10
150-
151-
# Check process is still running
152-
$mt5Running = Get-Process -Id $mt5Process.Id -ErrorAction SilentlyContinue
153-
if ($mt5Running) {
154-
Write-Host "MT5 process is still running with ID $($mt5Process.Id)"
155-
} else {
156-
Write-Host "Warning: MT5 process is no longer running"
157-
}
158-
159-
# Use the existing test script
160-
python test/integration/test_mt5_initialization.py
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+
200+
201+
202+
203+
204+
205+
MT5_WAIT_PERIOD: 5000 # Wait 5 seconds between attempts MT5_DEBUG: 1 MT5_TIMEOUT: 120000 # Increase timeout to 2 minutes MT5_HEADLESS: 1 env: python test/integration/test_mt5_initialization.py # Use the existing test script with expanded timeout } Write-Host "Warning: MT5 process is no longer running" } else { Write-Host "Process details: $($mt5Running | Format-List | Out-String)" Write-Host "MT5 process is still running with ID $($mt5Process.Id)" if ($mt5Running) { $mt5Running = Get-Process -Id $mt5Process.Id -ErrorAction SilentlyContinue # Check process is still running and get details Start-Sleep -Seconds 30 # Give MT5 more time to initialize - increase wait time Write-Host "Started MT5 process with ID $($mt5Process.Id)" $mt5Process = Start-Process -FilePath $env:MT5_PATH -ArgumentList "/portable", "/config:default.ini", "/skipupdate", "/minimize" -PassThru # Start MT5 manually with a combination of flags known to work better in CI $env:MT5_IPC_PORT = "8228" # Use a standard port for IPC $env:MT5_IPC_HOST = "localhost" # Start MT5 with more aggressive IPC settings Start-Sleep -Seconds 5 # Give system time to clean up processes } Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue Write-Host "Killing process $($_.Name) with ID $($_.Id)" Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | ForEach-Object { # Kill any existing MT5 processes run: | - name: Test MT5 initialization Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | Format-Table -AutoSize python test/integration/test_mt5_initialization.py
161206
env:
162207
MT5_HEADLESS: 1
163208
MT5_TIMEOUT: 60000

0 commit comments

Comments
 (0)