Skip to content

Commit 26f706a

Browse files
committed
test(rclone): 修复后台进程快速退出测试
1 parent c1e7d37 commit 26f706a

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

tests/RcloneOps.Tests.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,26 @@ Describe 'rclone-ops.ps1 JSON 配置生成逻辑' {
303303
$pidFile = Join-Path $TestDrive 'failed.pid'
304304
$logFile = Join-Path $TestDrive 'failed.log'
305305
Set-Content -LiteralPath $logFile -Value '模拟后台失败日志' -Encoding utf8NoBOM
306+
# 使用平台原生命令构造稳定的快速失败进程,避免 Windows CI 中 pwsh 冷启动超过探测窗口。
307+
$failedProcess = if ($IsWindows) {
308+
@{
309+
FilePath = 'cmd.exe'
310+
Arguments = @('/d', '/c', 'exit 7')
311+
ExpectedExitCode = 7
312+
}
313+
}
314+
else {
315+
@{
316+
FilePath = 'false'
317+
Arguments = @()
318+
ExpectedExitCode = 1
319+
}
320+
}
306321

307322
$warningMessages = @()
308-
$exitCode = Invoke-RcloneOpsProcess -FilePath 'pwsh' -Arguments @('-NoLogo', '-NoProfile', '-Command', 'exit 7') -Background -PidFile $pidFile -FailureLogFile $logFile -WarningVariable warningMessages
323+
$exitCode = Invoke-RcloneOpsProcess -FilePath $failedProcess.FilePath -Arguments $failedProcess.Arguments -Background -PidFile $pidFile -FailureLogFile $logFile -WarningVariable warningMessages
309324

310-
$exitCode | Should -Be 7
325+
$exitCode | Should -Be $failedProcess.ExpectedExitCode
311326
Test-Path -LiteralPath $pidFile | Should -BeFalse
312327
($warningMessages -join "`n") | Should -Match '模拟后台失败日志'
313328
}

0 commit comments

Comments
 (0)