SOMS/test_app_startup.ps1

70 lines
2.5 KiB
PowerShell
Raw Permalink Normal View History

#!/usr/bin/env pwsh
# 测试 SOMS 数据服务启动脚本
Write-Host "开始测试 SOMS 数据服务启动..." -ForegroundColor Green
# 检查关键文件是否存在
$appPath = "d:\SOMS\数据服务\SOMS数据服务.exe"
$memoryDll = "d:\SOMS\数据服务\Microsoft.Extensions.Caching.Memory.dll"
Write-Host "检查文件存在性..." -ForegroundColor Yellow
if (Test-Path $appPath) {
Write-Host "✓ 应用程序文件存在: $appPath" -ForegroundColor Green
} else {
Write-Host "✗ 应用程序文件不存在: $appPath" -ForegroundColor Red
exit 1
}
if (Test-Path $memoryDll) {
Write-Host "✓ 内存缓存 DLL 存在: $memoryDll" -ForegroundColor Green
# 检查版本
$version = [System.Reflection.AssemblyName]::GetAssemblyName($memoryDll).Version
Write-Host " 版本: $version" -ForegroundColor Cyan
if ($version.Major -eq 6 -and $version.Minor -eq 0) {
Write-Host "✓ 版本正确 (6.0.x.x)" -ForegroundColor Green
} else {
Write-Host "✗ 版本不正确,期望 6.0.x.x实际 $version" -ForegroundColor Red
}
} else {
Write-Host "✗ 内存缓存 DLL 不存在: $memoryDll" -ForegroundColor Red
exit 1
}
Write-Host "`n准备启动应用程序进行测试..." -ForegroundColor Yellow
Write-Host "注意:应用程序将在 10 秒后自动关闭以避免长时间运行" -ForegroundColor Cyan
# 启动应用程序并监控输出
try {
$process = Start-Process -FilePath $appPath -WorkingDirectory "d:\SOMS\数据服务" -PassThru -WindowStyle Hidden
Write-Host "应用程序已启动PID: $($process.Id)" -ForegroundColor Green
# 等待 10 秒
Start-Sleep -Seconds 10
# 检查进程是否仍在运行
if (!$process.HasExited) {
Write-Host "✓ 应用程序成功启动并运行中" -ForegroundColor Green
# 优雅关闭
$process.CloseMainWindow()
Start-Sleep -Seconds 2
if (!$process.HasExited) {
Write-Host "强制关闭应用程序..." -ForegroundColor Yellow
$process.Kill()
}
Write-Host "✓ 测试完成:应用程序启动成功!" -ForegroundColor Green
} else {
Write-Host "✗ 应用程序启动后立即退出,退出代码: $($process.ExitCode)" -ForegroundColor Red
Write-Host "请检查日志文件获取详细错误信息" -ForegroundColor Yellow
}
} catch {
Write-Host "✗ 启动应用程序时发生错误: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "`n测试完成。" -ForegroundColor Green