Add integration tests for inofity limits

inotify exposes a /proc interface to limit kernel memory usage. If those
limits are set too low, inotify cannot add all watches. The integration
test verifies, that Inotify yields an error in that case.
This commit is contained in:
T. R. Bernstein
2026-03-12 14:52:33 +01:00
parent ffac6d17a5
commit 76f91f67a6
5 changed files with 123 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
import Foundation
func withInotifyWatchLimit(of limit: Int, _ body: () async throws -> Void) async throws {
let confPath = URL(filePath: "/proc/sys/fs/inotify")
let filenames = ["max_user_watches", "max_user_instances", "max_queued_events"]
var previousLimits: [String: String] = [:]
for filename in filenames {
let filePath = confPath.appending(path: filename)
let currentLimit = try String(contentsOf: filePath, encoding: .utf8)
previousLimits[filename] = currentLimit
try "\(limit)".write(to: filePath, atomically: false, encoding: .utf8)
}
try await body()
for filename in filenames {
let filePath = confPath.appending(path: filename)
guard let previousLimit = previousLimits[filename] else { continue }
try previousLimit.write(to: filePath, atomically: false, encoding: .utf8)
}
}