]> source.dussan.org Git - jgit.git/commitdiff
Ensure RacyGitTests don't raise false negatives 60/126160/1
authorChristian Halstrick <christian.halstrick@sap.com>
Tue, 17 Jul 2018 10:00:04 +0000 (12:00 +0200)
committerChristian Halstrick <christian.halstrick@sap.com>
Tue, 17 Jul 2018 10:00:04 +0000 (12:00 +0200)
RacyGitTests depend on filesystem timer resolution. We wait for a file
system timer tick, remember that time as t1, modify a file and assume
that this file has a lastmodified of t1.

If this assumption is not fulfilled then ignore the test result.

Bug: 526111
Change-Id: Ia38b7d2f99171ef54b8f9fe5be343cf9fcfd3971

org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java

index 8d9ccab1bd8c170f560dbb5b226fa49960dab4e7..3542dfad2d1e10bbd956de41ffcd0bff75be78ac 100644 (file)
@@ -45,6 +45,7 @@ package org.eclipse.jgit.lib;
 import static java.lang.Long.valueOf;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
 
 import java.io.File;
 import java.io.FileOutputStream;
@@ -157,10 +158,13 @@ public class RacyGitTests extends RepositoryTestCase {
                // Remember the last modTime of index file. All modifications times of
                // further modification are translated to this value so it looks that
                // files have been modified in the same time slot as the index file
-               modTimes.add(Long.valueOf(db.getIndexFile().lastModified()));
+               long indexMod = db.getIndexFile().lastModified();
+               modTimes.add(Long.valueOf(indexMod));
 
                // modify one file
-               addToWorkDir("a", "a2");
+               long aMod = addToWorkDir("a", "a2").lastModified();
+               assumeTrue(aMod == indexMod);
+
                // now update the index the index. 'a' has to be racily clean -- because
                // it's modification time is exactly the same as the previous index file
                // mod time.