27 lines
2.0 KiB
Swift
27 lines
2.0 KiB
Swift
import Foundation
|
|
|
|
@main struct ProcessSelectionChecks {
|
|
static func main() {
|
|
let id = ProcessIdentity(pid: 42, seconds: 100, microseconds: 0)
|
|
let row = ProcessMetrics(id: id, name: "worker", path: "/test/worker", cpu: 0.2,
|
|
residentBytes: 10, threads: 1, restricted: false)
|
|
let live = ProcessSnapshot(date: Date(), enumerated: 1, readable: 1, rows: [row], failed: false)
|
|
let filtered = ProcessTableProjection.rows(live.rows, query: "does-not-match", sorting: [], order: [])
|
|
precondition(filtered.isEmpty)
|
|
precondition(ProcessTableProjection.exitedSelection(id, in: live) == nil, "Filtered selection is still alive")
|
|
precondition(ProcessTableProjection.exitedSelection(nil, in: live) == nil)
|
|
precondition(ProcessTableProjection.exitedSelection(id, in: nil) == nil)
|
|
let failed = ProcessSnapshot(date: Date(), enumerated: 0, readable: 0, rows: [], failed: true)
|
|
precondition(ProcessTableProjection.exitedSelection(id, in: failed) == nil, "A failed read cannot prove exit")
|
|
let exited = ProcessSnapshot(date: Date(), enumerated: 0, readable: 0, rows: [], failed: false)
|
|
precondition(ProcessTableProjection.exitedSelection(id, in: exited) == id)
|
|
let reused = ProcessIdentity(pid: 42, seconds: 101, microseconds: 0)
|
|
let replacement = ProcessMetrics(id: reused, name: row.name, path: row.path, cpu: nil,
|
|
residentBytes: nil, threads: nil, restricted: true)
|
|
let recycled = ProcessSnapshot(date: Date(), enumerated: 1, readable: 0, rows: [replacement], failed: false)
|
|
precondition(ProcessTableProjection.exitedSelection(id, in: recycled) == id, "PID reuse cannot keep the previous process alive")
|
|
precondition(ProcessTableProjection.exitedSelection(reused, in: recycled) == nil)
|
|
print("PASS: filtered/live selection, absent selection/snapshot, failed enumeration, actual exit and PID reuse")
|
|
}
|
|
}
|