Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions Tests/SwiftDocCUtilitiesTests/DirectoryMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,25 @@ 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.
private func monitorNoUpdates(url: URL, testBlock: @escaping () throws -> Void, file: StaticString = #filePath, line: UInt = #line) throws {
let fileUpdateEvent = expectation(description: "Unexpectedly triggered an update event")
// This test does not expect any file change events
fileUpdateEvent.isInverted = true

let monitor = try DirectoryMonitor(root: url) { rootURL, url in
XCTFail("Did produce file update event for a hidden file", file: file, line: line)
fileUpdateEvent.fulfill()
}

try monitor.start()
defer {
monitor.stop()
}

let didNotTriggerUpdateForHiddenFile = expectation(description: "Doesn't trigger update")
DispatchQueue.global().async {
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) {
didNotTriggerUpdateForHiddenFile.fulfill()
}

wait(for: [didNotTriggerUpdateForHiddenFile], timeout: 20)
// For 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.
waitForExpectations(timeout: 1.5)
}
#endif

Expand Down