summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-07-10 16:17:21 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-07-19 14:45:56 +0200
commit9eff45e4f2e54a08a04b91aae47b5245f74c0582 (patch)
treefe68f6750c2ccc1ca707bae5da220e4db00ee7df /org.eclipse.jgit.test/tst
parentbce4ac97fabc5ea3627c06e24f7a2fab38642514 (diff)
downloadjgit-9eff45e4f2e54a08a04b91aae47b5245f74c0582.tar.gz
jgit-9eff45e4f2e54a08a04b91aae47b5245f74c0582.zip
Fix FileSnapshotTests for filesystem with high timestamp resolution
When filesystem timestamp resolution is very high some tests don't work since runtime of the test setup is too long to reach a racily clean FileSnapshot. Hence skip these tests when timestamp resolution is higher than 10 millisecond. Change-Id: Ie47dd10eda22037b5c1ebff6b6becce0654ea807 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java
index f228fb330b..1dea470848 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java
@@ -52,7 +52,9 @@ import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.FileTime;
+import java.time.Duration;
import java.time.Instant;
+import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
@@ -66,12 +68,14 @@ public class FileSnapshotTest {
private Path trash;
+ private Duration fsTimerResolution;
+
@Before
public void setUp() throws Exception {
trash = Files.createTempDirectory("tmp_");
// measure timer resolution before the test to avoid time critical tests
// are affected by time needed for measurement
- FS.getFsTimerResolution(trash.getParent());
+ fsTimerResolution = FS.getFsTimerResolution(trash.getParent());
}
@Before
@@ -114,10 +118,14 @@ public class FileSnapshotTest {
*/
@Test
public void testNewFileWithWait() throws Exception {
+ // if filesystem timestamp resolution is high the snapshot won't be
+ // racily clean
+ Assume.assumeTrue(
+ fsTimerResolution.compareTo(Duration.ofMillis(10)) > 0);
Path f1 = createFile("newfile");
waitNextTick(f1);
FileSnapshot save = FileSnapshot.save(f1.toFile());
- Thread.sleep(1500);
+ TimeUnit.NANOSECONDS.sleep(fsTimerResolution.dividedBy(2).toNanos());
assertTrue(save.isModified(f1.toFile()));
}
@@ -128,6 +136,10 @@ public class FileSnapshotTest {
*/
@Test
public void testNewFileNoWait() throws Exception {
+ // if filesystem timestamp resolution is high the snapshot won't be
+ // racily clean
+ Assume.assumeTrue(
+ fsTimerResolution.compareTo(Duration.ofMillis(10)) > 0);
Path f1 = createFile("newfile");
FileSnapshot save = FileSnapshot.save(f1.toFile());
assertTrue(save.isModified(f1.toFile()));