Try to fix issue with MainTest.file is modified if it is not formatted (#309)
Summary:
Pull Request resolved: https://github.com/facebookincubator/ktfmt/pull/309
GitHub actions are failing on this test case:
https://github.com/facebookincubator/ktfmt/runs/6005912425?check_suite_focus=true#step:4:93991
Looks like recent optimizations, and a different order of running stuff can make this test run too fast? I'm not sure, but I'm going to give this a try. If not, I'll run some other debugging ideas for this test.
Reviewed By: cgrushko
Differential Revision: D35611158
fbshipit-source-id: 816cecf57ba0b8451bdfe6d5f4122b707cc17c57
diff --git a/core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt b/core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt
index 51972ab..f4d2c27 100644
--- a/core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt
+++ b/core/src/test/java/com/facebook/ktfmt/cli/MainTest.kt
@@ -188,6 +188,8 @@
val lastModifiedTimeBeforeRunningFormatter =
Files.getLastModifiedTime(unformattedFilePath).toMillis()
+ // The test may run under 1ms, and we need to make sure the new file timestamp will be different
+ Thread.sleep(100)
Main(emptyInput, PrintStream(out), PrintStream(err), arrayOf(unformattedFile.toString())).run()
val lastModifiedTimeAfterRunningFormatter =
Files.getLastModifiedTime(unformattedFilePath).toMillis()