Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2019-06-18 09:32:59 +0000
committerMatthias Sohn2019-09-03 08:37:30 +0000
commit1de117780036b14db025ee3a5fa4ebd285a826cf (patch)
tree787e3a58d6a7894e50cbf6788f48da21415af15a
parent3712b0a3b1b428ec446d83f13e544f605d26220e (diff)
downloadjgit-1de117780036b14db025ee3a5fa4ebd285a826cf.tar.gz
jgit-1de117780036b14db025ee3a5fa4ebd285a826cf.tar.xz
jgit-1de117780036b14db025ee3a5fa4ebd285a826cf.zip
Fix RacyGitTests#testRacyGitDetection
This test case assumed file system timestamp resolution of 1 second. On filesystems with a finer resolution this test fails since the index entry is only smudged if the file index entry's lastModified and the lastModified of the git index itself are within the same filesystem timer tick. Fix this by ensuring that these timestamps are identical which should work for any filesystem timer resolution. Bug: 548188 Change-Id: Id84d59e1cfeb48fa008f8f27f2f892c4f73985de Signed-off-by: Matthias Sohn <matthias.sohn@sap.com> Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> (cherry picked from commit 1159f9dd7c80a53c2509cd75d997a6afed37f9a6)
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java37
1 files changed, 26 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
index 8b1d5cc37d..27939b212f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
@@ -44,6 +44,7 @@ package org.eclipse.jgit.lib;
import static java.lang.Long.valueOf;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -52,10 +53,12 @@ import java.io.IOException;
import java.util.TreeSet;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.FileTreeIteratorWithTimeControl;
import org.eclipse.jgit.treewalk.NameConflictTreeWalk;
+import org.eclipse.jgit.treewalk.WorkingTreeOptions;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Test;
@@ -136,8 +139,8 @@ public class RacyGitTests extends RepositoryTestCase {
fsTick(db.getIndexFile());
// create two files
- File a = addToWorkDir("a", "a");
- File b = addToWorkDir("b", "b");
+ File a = writeToWorkDir("a", "a");
+ File b = writeToWorkDir("b", "b");
assertTrue(a.setLastModified(b.lastModified()));
assertTrue(b.setLastModified(b.lastModified()));
@@ -157,23 +160,35 @@ public class RacyGitTests extends RepositoryTestCase {
fsTick(db.getIndexFile());
// Create a racy git situation. This is a situation that the index is
- // updated and then a file is modified within a second. By changing the
- // index file artificially, we create a fake racy situation.
- File updatedA = addToWorkDir("a", "a2");
- assertTrue(updatedA.setLastModified(updatedA.lastModified() + 100));
+ // updated and then a file is modified within the same tick of the
+ // filesystem timestamp resolution. By changing the index file
+ // artificially, we create a fake racy situation.
+ File updatedA = writeToWorkDir("a", "a2");
+ long newLastModified = updatedA.lastModified() + 100;
+ assertTrue(updatedA.setLastModified(newLastModified));
resetIndex(new FileTreeIterator(db));
- assertTrue(db.getIndexFile()
- .setLastModified(updatedA.lastModified() + 90));
+ assertTrue(db.getIndexFile().setLastModified(newLastModified));
- db.readDirCache();
- // although racily clean a should not be reported as being dirty
+ DirCache dc = db.readDirCache();
+ // check index state: although racily clean a should not be reported as
+ // being dirty since we forcefully reset the index to match the working
+ // tree
assertEquals(
"[a, mode:100644, time:t1, smudged, length:0, content:a2]"
+ "[b, mode:100644, time:t0, length:1, content:b]",
indexState(SMUDGE | MOD_TIME | LENGTH | CONTENT));
+
+ // compare state of files in working tree with index to check that
+ // FileTreeIterator.isModified() works as expected
+ FileTreeIterator f = new FileTreeIterator(db.getWorkTree(), db.getFS(),
+ db.getConfig().get(WorkingTreeOptions.KEY));
+ assertTrue(f.findFile("a"));
+ try (ObjectReader reader = db.newObjectReader()) {
+ assertFalse(f.isModified(dc.getEntry("a"), false, reader));
+ }
}
- private File addToWorkDir(String path, String content) throws IOException {
+ private File writeToWorkDir(String path, String content) throws IOException {
File f = new File(db.getWorkTree(), path);
FileOutputStream fos = new FileOutputStream(f);
try {

Back to the top