Files
ShadowsocksX-NG/ShadowsocksX-NG2/Tests/AgentLifecycleTests+CrashRecovery.swift
T
Qiu Yuzhou 827fb98be3 refactor(ng2): fix all swiftlint warnings
77 → 0 warnings. Split oversized functions and files: controller and
agent extension files, standalone RuleSet/ProxySettingsFileStore/
SslocalListenSettings/LegacyImportService, test classes into topic
extensions. Regroup activation options into RuntimeDocumentOptions and
converter metadata into Provenance.

Runtime controller DI seams widen private → internal so the extension
files stay cohesive; new controller files are registered in the
architecture guard exemption list; Agent target adds RuleSet and
SslocalListenSettings to project.yml. Test JSON literals wrap inside
the string literal only.
2026-09-26 17:13:31 +08:00

36 lines
1.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Darwin
import XCTest
@testable import ShadowsocksX_NG2
extension AgentLifecycleTests {
// MARK: 崩溃恢复(D2)
func testSslocalCrashExitsNonZeroForKeepAliveReplay() throws {
try writeContract(ProxyRuntimeFixture.makeDocument())
let wrapper = try launchWrapper(behavior: "crash")
let exitStatus = try waitForExit(wrapper)
XCTAssertNotEqual(exitStatus, 0, "sslocal 崩溃 → wrapper 非零退出 → KeepAlive 重启重放")
// KeepAlive 重放语义:同一份契约再拉起一次即恢复(stub 换回常驻行为)。
let replay = try launchWrapper(behavior: "run")
XCTAssertTrue(
try waitUntil { self.stateLog().components(separatedBy: "invoked:").count >= 3 },
"重放应再次拉起 sslocal")
kill(replay.processIdentifier, SIGTERM)
XCTAssertEqual(try waitForExit(replay), 0)
}
func testUnexpectedCleanChildExitAlsoCountsAsLoss() throws {
try writeContract(ProxyRuntimeFixture.makeDocument())
let wrapper = try launchWrapper(behavior: "exit0")
let exitStatus = try waitForExit(wrapper)
XCTAssertNotEqual(
exitStatus, 0, "sslocal 自行退出(即使干净)也应触发重放而非静默下线")
}
}