From 2370bed14549d8d0a643cae4c8d769e5a78d46cd Mon Sep 17 00:00:00 2001 From: Prajwal Nadig Date: Wed, 29 Oct 2025 11:22:53 +0000 Subject: [PATCH] Speed up directory monitoring tests The directory monitoring tests check for whether the documentation is rebuilt if the documentation catalog is edited when running a live server with `docc preview`. These tests assumed an extremely generous timeout for receiving the directory change signal, and ran much slower than the rest of the test suite. The timeouts have been reduced to a more reasonable threshold that succeeds even with throttled resources on a single-core machine. --- .../DirectoryMonitorTests.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift b/Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift index 555d25822..76f2038a4 100644 --- a/Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift +++ b/Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift @@ -88,7 +88,8 @@ class DirectoryMonitorTests: XCTestCase { } } - /// - Warning: Please do not overuse this method as it takes 10s of wait time and can potentially slow down running the test suite. + /// - Warning: Please do not overuse this method as it takes 2 seconds of + /// wait time per invocation, and can potentially slow down the test suite. private func monitorNoUpdates(url: URL, testBlock: @escaping () throws -> Void, file: StaticString = #filePath, line: UInt = #line) throws { let monitor = try DirectoryMonitor(root: url) { rootURL, url in XCTFail("Did produce file update event for a hidden file", file: file, line: line) @@ -104,12 +105,15 @@ class DirectoryMonitorTests: XCTestCase { try? testBlock() } - // For the test purposes we assume a file change event will be delivered within generous 10 seconds. - DispatchQueue.global().asyncAfter(deadline: .now() + 10) { + // For the test purposes we assume a file change event will be delivered within 1.5 seconds. + // This also aligns with the `monitor` method above, that ensures that file change events + // in tests are received within 1.5 seconds. If this works too eagerly, then the other tests + // in this suite will fail. + DispatchQueue.global().asyncAfter(deadline: .now() + 1.5) { didNotTriggerUpdateForHiddenFile.fulfill() } - wait(for: [didNotTriggerUpdateForHiddenFile], timeout: 20) + wait(for: [didNotTriggerUpdateForHiddenFile], timeout: 2) } #endif