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

Attempt to make filesystem tests less flaky #1181

Merged
merged 2 commits into from Jan 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -31,6 +31,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlin.test.fail
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

Expand Down Expand Up @@ -2356,20 +2357,28 @@ abstract class AbstractFileSystemTest(
* Returns the earliest file system time that could be recorded for an event occurring at this
* instant. This truncates fractional seconds because most host file systems do not use precise
* timestamps for file metadata.
*
* It also pads the result by 200 milliseconds because the host and file system may use different
* clocks, allowing the time on the CPU to drift ahead of the time on the file system.
*/
private fun Instant.minFileSystemTime(): Instant {
return Instant.fromEpochSeconds(epochSeconds)
val paddedInstant = minus(200.milliseconds)
return Instant.fromEpochSeconds(paddedInstant.epochSeconds)
}

/**
* Returns the latest file system time that could be recorded for an event occurring at this
* instant. This adds 2 seconds and truncates fractional seconds because file systems may defer
* assigning the timestamp.
*
* It also pads the result by 200 milliseconds because the host and file system may use different
* clocks, allowing the time on the CPU to drift behind the time on the file system.
*
* https://docs.microsoft.com/en-us/windows/win32/sysinfo/file-times
*/
private fun Instant.maxFileSystemTime(): Instant {
return Instant.fromEpochSeconds(plus(2.seconds).epochSeconds)
val paddedInstant = plus(200.milliseconds)
return Instant.fromEpochSeconds(paddedInstant.plus(2.seconds).epochSeconds)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why go via epoch seconds?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s attempting to drop precision, consistent with what FAT32 and friends do.

}

/**
Expand Down