Skip to content

Commit b2ca12b

Browse files
committed
test it again
1 parent 48f1226 commit b2ca12b

File tree

1 file changed

+131
-89
lines changed

1 file changed

+131
-89
lines changed

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

Lines changed: 131 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -52,158 +52,200 @@ jobs:
5252
Write-Host "Searching for MT5 installation..."
5353
$foundPaths = Get-ChildItem -Path "C:\" -Filter "terminal*.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
5454
foreach ($path in $foundPaths) {
55-
Write-Host "Found MT5 at: $path"
56-
}
55+
Write-Host "Found MT5 at: $path" "C:\" -Filter "terminal.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
56+
}foundPaths += Get-ChildItem -Path "C:\" -Filter "terminal64.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
5757
5858
# Add details about system architecture
5959
$architecture = [System.Environment]::Is64BitOperatingSystem ? "64-bit" : "32-bit"
6060
Write-Host "System Architecture: $architecture"
6161
Write-Host "PowerShell Architecture: $([IntPtr]::Size * 8)-bit"
62-
63-
exit 1
64-
}
65-
62+
# Add details about system architecture
63+
exit 1tecture = [System.Environment]::Is64BitOperatingSystem ? "64-bit" : "32-bit"
64+
} Write-Host "System Architecture: $architecture"
65+
Write-Host "PowerShell Architecture: $([IntPtr]::Size * 8)-bit"
6666
- name: Install Python dependencies
67-
run: |
67+
run: |it 1
6868
python -m pip install --upgrade pip
6969
pip install MetaTrader5 pytest
70-
70+
- name: Install Python dependencies
7171
- name: Configure MT5 for headless operation
72-
run: |
72+
run: |on -m pip install --upgrade pip
7373
# Create data directory for portable mode
7474
$mt5DataDir = ".\MT5_Data"
7575
New-Item -Path $mt5DataDir -ItemType Directory -Force
76-
76+
n: |
7777
# Set environment variables for headless operation
7878
echo "MT5_HEADLESS=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
79-
echo "MT5_TIMEOUT=60000" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
79+
echo "MT5_TIMEOUT=60000" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Appendd
8080
echo "MT5_DEBUG=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
81-
82-
# Find MT5 path to pass to the test - check both 32-bit and 64-bit versions
83-
$mt5Path = ""
84-
$possiblePaths = @(
81+
# Set environment variables for headless operation
82+
# Find MT5 path to pass to the test - check both 32-bit and 64-bit versions in a 32-bit environmentAppend
83+
$mt5Path = ""EOUT=60000" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
84+
$possiblePaths = @(| Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
8585
"C:\Program Files\MetaTrader 5\terminal64.exe",
86-
"C:\Program Files\MetaTrader 5\terminal.exe",
86+
"C:\Program Files\MetaTrader 5\terminal.exe",h 32-bit and 64-bit versions
8787
".\MetaTrader 5\terminal64.exe",
88-
".\MetaTrader 5\terminal.exe",
88+
".\MetaTrader 5\terminal.exe",nal\MetaTrader5\terminal.exe",
8989
"$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal64.exe",
9090
"$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal.exe"
91-
)
92-
91+
) ".\MetaTrader 5\terminal64.exe", ".\MetaTrader 5\terminal64.exe",
92+
"$env:APPDATA\MetaQuotes\Terminal\MetaTrader5\terminal64.exe" ".\MetaTrader 5\terminal.exe",
9393
foreach ($path in $possiblePaths) {
94-
if (Test-Path $path) {
95-
$mt5Path = $path
94+
if (Test-Path $path) {terminal.exe"
95+
$mt5Path = $pathossiblePaths) {
9696
$mt5Dir = Split-Path -Parent $mt5Path
9797
echo "MT5_PATH=$mt5Path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
9898
echo "MT5_DIR=$mt5Dir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
99-
Write-Host "Setting MT5_PATH to $mt5Path"
100-
Write-Host "Setting MT5_DIR to $mt5Dir"
101-
99+
Write-Host "Setting MT5_PATH to $mt5Path"Path $env:GITHUB_ENV -Encoding utf8 -Append
100+
Write-Host "Setting MT5_DIR to $mt5Dir"Path $env:GITHUB_ENV -Encoding utf8 -Append
101+
Write-Host "Setting MT5_PATH to $mt5Path"echo "MT5_PATH=$mt5Path" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
102102
# Create minimal configuration file to help with headless mode
103-
$configLines = @(
104-
'[Common]',
105-
'Login=0',
106-
'ProxyEnable=0',
103+
$configLines = @(t5Path"
104+
'[Common]',mal configuration file to help with headless modeetting MT5_DIR to $mt5Dir"
105+
'Login=0', = @(
106+
'ProxyEnable=0',uration file to help with headless mode
107107
'CertCheckDisable=1',
108-
'AutoUpdate=0',
108+
'AutoUpdate=0',,
109109
'DisableStartupCompany=1',
110110
'EnableOpenCL=0',
111-
'News=0',
111+
'News=0',tartupCompany=1',kDisable=1',
112112
'StartupCompany=0',
113-
'Community=0',
113+
'Community=0',any=1',
114114
'AutoUpdate.Enable=0'
115-
)
115+
) 'Community=0', 'News=0',
116116
$configPath = Join-Path $mt5Dir "config\default.ini"
117117
New-Item -Path (Split-Path -Parent $configPath) -ItemType Directory -Force
118118
$configLines | Out-File -FilePath $configPath -Encoding utf8
119-
Write-Host "Created default config at $configPath"
120-
121-
break
122-
}
123-
}
124-
119+
Write-Host "Created default config at $configPath"temType Directory -Force
120+
$configLines | Out-File -FilePath $configPath -Encoding utf8$configPath = Join-Path $mt5Dir "config\default.ini"
121+
break-Host "Created default config at $configPath"tem -Path (Split-Path -Parent $configPath) -ItemType Directory -Force
122+
} $configLines | Out-File -FilePath $configPath -Encoding utf8
123+
} break Write-Host "Created default config at $configPath"
124+
}
125125
- name: Configure system for MT5 communication
126126
run: |
127127
# Create registry settings that can help with IPC communication
128128
Write-Host "Configuring system registry for MT5 communication"
129-
130-
# Ensure the MetaTrader registry key exists
129+
# Create registry settings that can help with IPC communicationme: Configure system for MT5 communication
130+
# Ensure the MetaTrader registry key exists MT5 communication"
131131
$registryPath = "HKCU:\Software\MetaQuotes"
132-
if (-not (Test-Path $registryPath)) {
132+
if (-not (Test-Path $registryPath)) {existsry for MT5 communication"
133133
New-Item -Path $registryPath -Force | Out-Null
134-
}
135-
134+
}f (-not (Test-Path $registryPath)) { Ensure the MetaTrader registry key exists
135+
New-Item -Path $registryPath -Force | Out-Null$registryPath = "HKCU:\Software\MetaQuotes"
136136
# Configure Terminal settings if needed
137137
$terminalPath = "$registryPath\Terminal"
138-
if (-not (Test-Path $terminalPath)) {
138+
if (-not (Test-Path $terminalPath)) {ed
139139
New-Item -Path $terminalPath -Force | Out-Null
140-
}
141-
140+
}f (-not (Test-Path $terminalPath)) { Configure Terminal settings if needed
141+
New-Item -Path $terminalPath -Force | Out-Null$terminalPath = "$registryPath\Terminal"
142142
# Set some registry values that may help with IPC
143143
Set-ItemProperty -Path $terminalPath -Name "HeadlessMode" -Value 1 -Type DWORD -Force
144144
Set-ItemProperty -Path $terminalPath -Name "AllowDllImport" -Value 1 -Type DWORD -Force
145-
146-
# Check if Python DLLs are accessible from the MT5 installation
145+
Set-ItemProperty -Path $terminalPath -Name "HeadlessMode" -Value 1 -Type DWORD -Force
146+
# Check if Python DLLs are accessible from the MT5 installationlue 1 -Type DWORD -Force
147147
$pythonDllPath = Join-Path (Split-Path -Parent (Get-Command python).Path) "python311.dll"
148-
if (Test-Path $pythonDllPath) {
149-
Write-Host "Python DLL found at: $pythonDllPath"
148+
if (Test-Path $pythonDllPath) {ssible from the MT5 installationlPath -Name "AllowDllImport" -Value 1 -Type DWORD -Force
149+
Write-Host "Python DLL found at: $pythonDllPath"Command python).Path) "python311.dll"
150150
# Copy Python DLL to MT5 directory to help with IPC
151-
if (Test-Path $env:MT5_DIR) {
151+
if (Test-Path $env:MT5_DIR) {at: $pythonDllPath"-Path -Parent (Get-Command python).Path) "python311.dll"
152152
Copy-Item -Path $pythonDllPath -Destination $env:MT5_DIR -Force
153153
Write-Host "Copied Python DLL to MT5 directory"
154-
}
155-
} else {
154+
} Copy-Item -Path $pythonDllPath -Destination $env:MT5_DIR -Force Copy Python DLL to MT5 directory to help with IPC
155+
} else {Write-Host "Copied Python DLL to MT5 directory"Test-Path $env:MT5_DIR) {
156156
Write-Host "Python DLL not found at expected location"
157-
}
158-
157+
} else { Write-Host "Copied Python DLL to MT5 directory"
158+
Write-Host "Python DLL not found at expected location" }
159159
- name: Debug environment
160-
run: |
160+
run: |Python DLL not found at expected location"
161161
Write-Host "Environment variables:"
162162
Get-ChildItem Env:
163-
163+
Write-Host "Environment variables:"me: Debug environment
164164
Write-Host "MT5 directory contents:"
165165
if (Test-Path $env:MT5_DIR) {
166166
Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullName
167-
}
168-
167+
}f (Test-Path $env:MT5_DIR) {
168+
Get-ChildItem -Path $env:MT5_DIR -Recurse -Depth 1 | Select-Object FullNameWrite-Host "MT5 directory contents:"
169169
Write-Host "System processes:"
170170
Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | Format-Table -AutoSize
171-
172-
- name: Test MT5 initialization
173-
run: |
174-
# Kill any existing MT5 processes
171+
Write-Host "System processes:" }
172+
- name: Test MT5 initialization{ $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | Format-Table -AutoSize
173+
run: |em processes:"
174+
# Kill any existing MT5 processesike "*MetaTrader*" -or $_.Name -like "*terminal*" } | Format-Table -AutoSize
175175
Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | ForEach-Object {
176176
Write-Host "Killing process $($_.Name) with ID $($_.Id)"
177-
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
178-
}
179-
177+
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue $_.Name -like "*terminal*" } | ForEach-Object {
178+
} Write-Host "Killing process $($_.Name) with ID $($_.Id)" Kill any existing MT5 processes
179+
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | ForEach-Object {
180180
# Give system time to clean up processes
181-
Start-Sleep -Seconds 5
182-
183-
# Start MT5 with more aggressive IPC settings
181+
Start-Sleep -Seconds 5 SilentlyContinue
182+
# Give system time to clean up processes}
183+
# Set explicit environment variables that can help with IPC
184184
$env:MT5_IPC_HOST = "localhost"
185185
$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"
186+
$env:MT5_64BIT = "0" # Force 32-bit mode for the Python module$env:MT5_IPC_HOST = "localhost"
187+
188+
# Create a custom settings file for the Python MT5 test
189+
$settingsContent = @"work better in CI
190+
[MT5]$mt5Process = Start-Process -FilePath $env:MT5_PATH -ArgumentList "/portable", "/config:default.ini", "/skipupdate", "/minimize" -PassThru
191+
path=$($env:MT5_PATH)d)"to work better in CI
192+
debug=1_PATH -ArgumentList "/portable", "/config:default.ini", "/skipupdate", "/minimize" -PassThru
193+
timeout=120000# Give MT5 more time to initialize - increase wait timeWrite-Host "Started MT5 process with ID $($mt5Process.Id)"
194+
headless=1
195+
ipc_host=localhost
196+
ipc_port=8228 still running and get detailsds 30
197+
"@tinue
198+
Set-Content -Path ".\mt5_settings.ini" -Value $settingsContent
199+
Host "MT5 process is still running with ID $($mt5Process.Id)"ing = Get-Process -Id $mt5Process.Id -ErrorAction SilentlyContinue
200+
# Start MT5 manually with a combination of flags known to work better in CIst | Out-String)"
201+
$startArgs = @("/portable") else { Write-Host "MT5 process is still running with ID $($mt5Process.Id)"
202+
Write-Host "Warning: MT5 process is no longer running" Write-Host "Process details: $($mt5Running | Format-List | Out-String)"
203+
# Add config argument if it exists
204+
$configPath = Join-Path (Split-Path -Parent $env:MT5_PATH) "config\default.ini"
205+
if (Test-Path $configPath) {Use the existing test script with expanded timeout
206+
$startArgs += "/config:default.ini"egration/test_mt5_initialization.py
201207
}
202-
203-
# Use the existing test script with expanded timeout
204-
python test/integration/test_mt5_initialization.py
205-
env:
206-
MT5_HEADLESS: 1
208+
: 1integration/test_mt5_initialization.py
209+
$startArgs += "/skipupdate"
210+
211+
212+
213+
214+
215+
216+
217+
218+
219+
220+
221+
222+
223+
224+
225+
226+
227+
228+
229+
230+
231+
232+
233+
234+
235+
236+
237+
238+
239+
240+
241+
242+
243+
244+
245+
246+
MT5_VERBOSE: 1 # Enable verbose logging MT5_64BIT: 0 # Force 32-bit mode MT5_WAIT_PERIOD: 10000 # Wait 10 seconds between attempts MT5_DEBUG: 1 MT5_TIMEOUT: 180000 # Increase timeout to 3 minutes MT5_HEADLESS: 1 env: python test/integration/test_mt5_initialization.py Write-Host "Running Python test script with expanded timeout..." # Use the existing test script with expanded timeout } Write-Host "Warning: MT5 process is no longer running" } else { $env:MT5_VERBOSE = "1" # Add verbose flag to the test script for more detailed output Get-Process | Where-Object { $_.Name -like "*MetaTrader*" -or $_.Name -like "*terminal*" } | Format-Table -AutoSize Write-Host "All running processes:" # List all processes to debug 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 45 Write-Host "Waiting 45 seconds for MT5 to initialize..." # 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 $startArgs -PassThru Write-Host "Starting MT5 with arguments: $startArgs" $startArgs += "/minimize"
247+
248+
MT5_WAIT_PERIOD: 5000 # Wait 5 seconds between attempts MT5_DEBUG: 1 MT5_HEADLESS: 1
207249
MT5_TIMEOUT: 120000 # Increase timeout to 2 minutes
208250
MT5_DEBUG: 1
209251
MT5_WAIT_PERIOD: 5000 # Wait 5 seconds between attempts

0 commit comments

Comments
 (0)