@@ -50,160 +50,160 @@ jobs:
50
50
51
51
# Search for installation
52
52
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
54
54
foreach ($path in $foundPaths) {
55
55
Write-Host "Found MT5 at: $path"
56
56
}
57
57
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"
60
60
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
62
67
run : |
63
68
python -m pip install --upgrade pip
64
69
pip install MetaTrader5 pytest
65
70
66
71
- name : Configure MT5 for headless operation
67
72
run : |
68
73
# Create data directory for portable mode
69
- $mt5DataDir = ".\MT5_Data"test
74
+ $mt5DataDir = ".\MT5_Data"
70
75
New-Item -Path $mt5DataDir -ItemType Directory -Force
71
- me: Configure MT5 for headless operation
76
+
72
77
# Set environment variables for headless operation
73
78
echo "MT5_HEADLESS=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
74
79
echo "MT5_TIMEOUT=60000" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
75
80
echo "MT5_DEBUG=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
76
81
77
82
# 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",
81
86
"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",
83
88
".\MetaTrader 5\terminal.exe",
84
89
"$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal64.exe",
85
90
"$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal.exe"
86
- ) "C:\Program Files\MetaTrader 5\terminal.exe",
87
- ".\MetaTrader 5\terminal64.exe",
91
+ )
92
+
88
93
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
91
96
$mt5Dir = Split-Path -Parent $mt5Path
92
97
echo "MT5_PATH=$mt5Path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
93
98
echo "MT5_DIR=$mt5Dir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
94
99
Write-Host "Setting MT5_PATH to $mt5Path"
95
100
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',
101
106
'ProxyEnable=0',
102
- 'CertCheckDisable=1',uration file to help with headless mode
107
+ 'CertCheckDisable=1',
103
108
'AutoUpdate=0',
104
109
'DisableStartupCompany=1',
105
110
'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
+ )
111
116
$configPath = Join-Path $mt5Dir "config\default.ini"
112
117
New-Item -Path (Split-Path -Parent $configPath) -ItemType Directory -Force
113
118
$configLines | Out-File -FilePath $configPath -Encoding utf8
114
119
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
+
120
125
- name : Configure system for MT5 communication
121
- run : |break
126
+ run : |
122
127
# Create registry settings that can help with IPC communication
123
128
Write-Host "Configuring system registry for MT5 communication"
124
129
125
130
# Ensure the MetaTrader registry key exists
126
131
$registryPath = "HKCU:\Software\MetaQuotes"
127
132
if (-not (Test-Path $registryPath)) {
128
- New-Item -Path $registryPath -Force | Out-Nullet-ChildItem Env:
133
+ New-Item -Path $registryPath -Force | Out-Null
129
134
}
130
- ents:"
135
+
131
136
# 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"
133
138
if (-not (Test-Path $terminalPath)) {
134
139
New-Item -Path $terminalPath -Force | Out-Null
135
140
}
136
- oSize
141
+
137
142
# Set some registry values that may help with IPC
138
143
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) {
144
149
Write-Host "Python DLL found at: $pythonDllPath"
145
150
# Copy Python DLL to MT5 directory to help with IPC
146
151
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
148
153
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"
152
157
}
153
- fully initialize before Python tries to connect
158
+
154
159
- name : Debug environment
155
160
run : |
156
161
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:"
160
165
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
162
167
}
163
168
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
177
171
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
206
205
env :
207
206
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