@@ -50,160 +50,160 @@ jobs:
5050
5151 # Search for installation
5252 Write-Host "Searching for MT5 installation..."
53- $foundPaths = Get-ChildItem -Path "C:\" -Filter "terminal64 .exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
53+ $foundPaths = Get-ChildItem -Path "C:\" -Filter "terminal* .exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
5454 foreach ($path in $foundPaths) {
5555 Write-Host "Found MT5 at: $path"
5656 }
5757
58- exit 1details about system architecture
59- } $architecture = [System.Environment]::Is64BitOperatingSystem ? "64-bit" : "32-bit"
58+ # Add details about system architecture
59+ $architecture = [System.Environment]::Is64BitOperatingSystem ? "64-bit" : "32-bit"
6060 Write-Host "System Architecture: $architecture"
61- - name : Install Python dependenciesecture: $([IntPtr]::Size * 8)-bit"
61+ Write-Host "PowerShell Architecture: $([IntPtr]::Size * 8)-bit"
62+
63+ exit 1
64+ }
65+
66+ - name : Install Python dependencies
6267 run : |
6368 python -m pip install --upgrade pip
6469 pip install MetaTrader5 pytest
6570
6671 - name : Configure MT5 for headless operation
6772 run : |
6873 # Create data directory for portable mode
69- $mt5DataDir = ".\MT5_Data"test
74+ $mt5DataDir = ".\MT5_Data"
7075 New-Item -Path $mt5DataDir -ItemType Directory -Force
71- me: Configure MT5 for headless operation
76+
7277 # Set environment variables for headless operation
7378 echo "MT5_HEADLESS=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7479 echo "MT5_TIMEOUT=60000" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7580 echo "MT5_DEBUG=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7681
7782 # Find MT5 path to pass to the test - check both 32-bit and 64-bit versions
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
83+ $mt5Path = ""
84+ $possiblePaths = @(
85+ "C:\Program Files\MetaTrader 5\terminal64.exe",
8186 "C:\Program Files\MetaTrader 5\terminal.exe",
82- ".\MetaTrader 5\terminal64.exe",t - check both 32-bit and 64-bit versions
87+ ".\MetaTrader 5\terminal64.exe",
8388 ".\MetaTrader 5\terminal.exe",
8489 "$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal64.exe",
8590 "$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal.exe"
86- ) "C:\Program Files\MetaTrader 5\terminal.exe",
87- ".\MetaTrader 5\terminal64.exe",
91+ )
92+
8893 foreach ($path in $possiblePaths) {
89- if (Test-Path $path) {es\Terminal\MetaTrader5\terminal64.exe",
90- $mt5Path = $pathQuotes\Terminal\MetaTrader5\terminal.exe"
94+ if (Test-Path $path) {
95+ $mt5Path = $path
9196 $mt5Dir = Split-Path -Parent $mt5Path
9297 echo "MT5_PATH=$mt5Path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
9398 echo "MT5_DIR=$mt5Dir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
9499 Write-Host "Setting MT5_PATH to $mt5Path"
95100 Write-Host "Setting MT5_DIR to $mt5Dir"
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"
101+
102+ # Create minimal configuration file to help with headless mode
103+ $configLines = @(
104+ '[Common]',
105+ 'Login=0',
101106 'ProxyEnable=0',
102- 'CertCheckDisable=1',uration file to help with headless mode
107+ 'CertCheckDisable=1',
103108 'AutoUpdate=0',
104109 'DisableStartupCompany=1',
105110 'EnableOpenCL=0',
106- 'News=0',ble=0',
107- 'StartupCompany=0',',
108- 'Community=0',,
109- 'AutoUpdate.Enable=0'y=1',
110- ) 'EnableOpenCL=0',
111+ 'News=0',
112+ 'StartupCompany=0',
113+ 'Community=0',
114+ 'AutoUpdate.Enable=0'
115+ )
111116 $configPath = Join-Path $mt5Dir "config\default.ini"
112117 New-Item -Path (Split-Path -Parent $configPath) -ItemType Directory -Force
113118 $configLines | Out-File -FilePath $configPath -Encoding utf8
114119 Write-Host "Created default config at $configPath"
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+
121+ break
122+ }
123+ }
124+
120125 - name : Configure system for MT5 communication
121- run : |break
126+ run : |
122127 # Create registry settings that can help with IPC communication
123128 Write-Host "Configuring system registry for MT5 communication"
124129
125130 # Ensure the MetaTrader registry key exists
126131 $registryPath = "HKCU:\Software\MetaQuotes"
127132 if (-not (Test-Path $registryPath)) {
128- New-Item -Path $registryPath -Force | Out-Nullet-ChildItem Env:
133+ New-Item -Path $registryPath -Force | Out-Null
129134 }
130- ents:"
135+
131136 # Configure Terminal settings if needed
132- $terminalPath = "$registryPath\Terminal" Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullName
137+ $terminalPath = "$registryPath\Terminal"
133138 if (-not (Test-Path $terminalPath)) {
134139 New-Item -Path $terminalPath -Force | Out-Null
135140 }
136- oSize
141+
137142 # Set some registry values that may help with IPC
138143 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+ Set-ItemProperty -Path $terminalPath -Name "AllowDllImport" -Value 1 -Type DWORD -Force
145+
146+ # Check if Python DLLs are accessible from the MT5 installation
147+ $pythonDllPath = Join-Path (Split-Path -Parent (Get-Command python).Path) "python311.dll"
148+ if (Test-Path $pythonDllPath) {
144149 Write-Host "Python DLL found at: $pythonDllPath"
145150 # Copy Python DLL to MT5 directory to help with IPC
146151 if (Test-Path $env:MT5_DIR) {
147- Copy-Item -Path $pythonDllPath -Destination $env:MT5_DIR -ForceStart-Sleep -Seconds 5
152+ Copy-Item -Path $pythonDllPath -Destination $env:MT5_DIR -Force
148153 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)"
154+ }
155+ } else {
156+ Write-Host "Python DLL not found at expected location"
152157 }
153- fully initialize before Python tries to connect
158+
154159 - name : Debug environment
155160 run : |
156161 Write-Host "Environment variables:"
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)"
162+ Get-ChildItem Env:
163+
164+ Write-Host "MT5 directory contents:"
160165 if (Test-Path $env:MT5_DIR) {
161- Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullNameWrite-Host "Warning: MT5 process is no longer running"
166+ Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullName
162167 }
163168
164- Write-Host "System processes:"isting test script
165-
166-
167-
168-
169-
170-
171-
172-
173-
174-
175-
176-
169+ Write-Host "System processes:"
170+ Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | Format-Table -AutoSize
177171
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
172+ - name : Test MT5 initialization
173+ run : |
174+ # Kill any existing MT5 processes
175+ Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | ForEach-Object {
176+ Write-Host "Killing process $($_.Name) with ID $($_.Id)"
177+ Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
178+ }
179+
180+ # Give system time to clean up processes
181+ Start-Sleep -Seconds 5
182+
183+ # Start MT5 with more aggressive IPC settings
184+ $env:MT5_IPC_HOST = "localhost"
185+ $env:MT5_IPC_PORT = "8228" # Use a standard port for IPC
186+
187+ # Start MT5 manually with a combination of flags known to work better in CI
188+ $mt5Process = Start-Process -FilePath $env:MT5_PATH -ArgumentList "/portable", "/config:default.ini", "/skipupdate", "/minimize" -PassThru
189+ Write-Host "Started MT5 process with ID $($mt5Process.Id)"
190+
191+ # Give MT5 more time to initialize - increase wait time
192+ Start-Sleep -Seconds 30
193+
194+ # Check process is still running and get details
195+ $mt5Running = Get-Process -Id $mt5Process.Id -ErrorAction SilentlyContinue
196+ if ($mt5Running) {
197+ Write-Host "MT5 process is still running with ID $($mt5Process.Id)"
198+ Write-Host "Process details: $($mt5Running | Format-List | Out-String)"
199+ } else {
200+ Write-Host "Warning: MT5 process is no longer running"
201+ }
202+
203+ # Use the existing test script with expanded timeout
204+ python test/integration/test_mt5_initialization.py
206205 env :
207206 MT5_HEADLESS : 1
208- MT5_TIMEOUT : 60000
209- MT5_DEBUG : 1
207+ MT5_TIMEOUT : 120000 # Increase timeout to 2 minutes
208+ MT5_DEBUG : 1
209+ MT5_WAIT_PERIOD : 5000 # Wait 5 seconds between attempts
0 commit comments