Skip to content

Commit 304804b

Browse files
authored
Speed up directory monitoring tests (#1325)
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 7db36ad commit 304804b

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,25 @@ 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.
9291
private func monitorNoUpdates(url: URL, testBlock: @escaping () throws -> Void, file: StaticString = #filePath, line: UInt = #line) throws {
92+
let fileUpdateEvent = expectation(description: "Unexpectedly triggered an update event")
93+
// This test does not expect any file change events
94+
fileUpdateEvent.isInverted = true
95+
9396
let monitor = try DirectoryMonitor(root: url) { rootURL, url in
94-
XCTFail("Did produce file update event for a hidden file", file: file, line: line)
97+
fileUpdateEvent.fulfill()
9598
}
9699

97100
try monitor.start()
98101
defer {
99102
monitor.stop()
100103
}
101104

102-
let didNotTriggerUpdateForHiddenFile = expectation(description: "Doesn't trigger update")
103-
DispatchQueue.global().async {
104-
try? testBlock()
105-
}
106-
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) {
109-
didNotTriggerUpdateForHiddenFile.fulfill()
110-
}
111-
112-
wait(for: [didNotTriggerUpdateForHiddenFile], timeout: 20)
105+
// For test purposes, we assume a file change event will be delivered within 1.5 seconds.
106+
// This also aligns with the `monitor()` method above, that ensures that file change events
107+
// in tests are received within 1.5 seconds. If this works too eagerly, then the other tests
108+
// in this suite will fail.
109+
waitForExpectations(timeout: 1.5)
113110
}
114111
#endif
115112

0 commit comments

Comments
 (0)