Skip to content

Commit

Permalink
Fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Aug 13, 2024
1 parent 23e6139 commit d58915a
Showing 1 changed file with 12 additions and 10 deletions.
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 10 seconds 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 10 seconds 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

0 comments on commit d58915a

Please sign in to comment.