Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NIOFileSystem flaky tests #2842

Merged
merged 2 commits into from
Aug 13, 2024
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
22 changes: 12 additions & 10 deletions Tests/NIOFileSystemIntegrationTests/FileHandleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1256,14 +1256,15 @@ final class FileHandleTests: XCTestCase {
lastAccess: nil,
lastDataModification: nil
)
let estimatedCurrentTime = Date.now.timeIntervalSince1970
let estimatedCurrentTimeInSeconds = Date.now.timeIntervalSince1970

// Assert that the times are equal to the current time, with up to a second difference (to avoid timing flakiness).
// Assert that the times are equal to the current time, with up to a second difference
// to avoid timing flakiness. Both the last accessed and last modification times should
// also equal each other.
actualLastAccessTime = try await handle.info().lastAccessTime
XCTAssertEqual(Float(actualLastAccessTime.seconds), Float(estimatedCurrentTime), accuracy: 1)

XCTAssertEqual(Double(actualLastAccessTime.seconds), estimatedCurrentTimeInSeconds, accuracy: 1)
actualLastDataModificationTime = try await handle.info().lastDataModificationTime
XCTAssertEqual(Float(actualLastDataModificationTime.seconds), Float(estimatedCurrentTime), accuracy: 1)
XCTAssertEqual(actualLastDataModificationTime.seconds, actualLastAccessTime.seconds)
}
}

Expand All @@ -1283,14 +1284,15 @@ final class FileHandleTests: XCTestCase {
XCTAssertEqual(actualLastDataModificationTime, FileInfo.Timespec(seconds: 1, nanoseconds: 0))

try await handle.touch()
let estimatedCurrentTime = Date.now.timeIntervalSince1970
let estimatedCurrentTimeInSeconds = Date.now.timeIntervalSince1970

// Assert that the times are equal to the current time, with up to a second difference (to avoid timing flakiness).
// Assert that the times are equal to the current time, with up to a second difference
// to avoid timing flakiness. Both the last accessed and last modification times should
// also equal each other.
actualLastAccessTime = try await handle.info().lastAccessTime
XCTAssertEqual(Float(actualLastAccessTime.seconds), Float(estimatedCurrentTime), accuracy: 1)

XCTAssertEqual(Double(actualLastAccessTime.seconds), estimatedCurrentTimeInSeconds, accuracy: 1)
actualLastDataModificationTime = try await handle.info().lastDataModificationTime
XCTAssertEqual(Float(actualLastDataModificationTime.seconds), Float(estimatedCurrentTime), accuracy: 1)
XCTAssertEqual(actualLastDataModificationTime.seconds, actualLastAccessTime.seconds)
}
}
}
Expand Down
Loading