Skip to content

Commit 2370bed

Browse files
committed
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.
1 parent e15f4e1 commit 2370bed

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class DirectoryMonitorTests: XCTestCase {
8888
}
8989
}
9090

91-
/// - Warning: Please do not overuse this method as it takes 10s of wait time and can potentially slow down running the test suite.
91+
/// - Warning: Please do not overuse this method as it takes 2 seconds of
92+
/// wait time per invocation, and can potentially slow down the test suite.
9293
private func monitorNoUpdates(url: URL, testBlock: @escaping () throws -> Void, file: StaticString = #filePath, line: UInt = #line) throws {
9394
let monitor = try DirectoryMonitor(root: url) { rootURL, url in
9495
XCTFail("Did produce file update event for a hidden file", file: file, line: line)
@@ -104,12 +105,15 @@ class DirectoryMonitorTests: XCTestCase {
104105
try? testBlock()
105106
}
106107

107-
// For the test purposes we assume a file change event will be delivered within generous 10 seconds.
108-
DispatchQueue.global().asyncAfter(deadline: .now() + 10) {
108+
// For the test purposes we assume a file change event will be delivered within 1.5 seconds.
109+
// This also aligns with the `monitor` method above, that ensures that file change events
110+
// in tests are received within 1.5 seconds. If this works too eagerly, then the other tests
111+
// in this suite will fail.
112+
DispatchQueue.global().asyncAfter(deadline: .now() + 1.5) {
109113
didNotTriggerUpdateForHiddenFile.fulfill()
110114
}
111115

112-
wait(for: [didNotTriggerUpdateForHiddenFile], timeout: 20)
116+
wait(for: [didNotTriggerUpdateForHiddenFile], timeout: 2)
113117
}
114118
#endif
115119

0 commit comments

Comments
 (0)