aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2019-06-04 18:03:26 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-06-05 00:48:07 +0200
commitb2ee9cfbc3b757dc7e7896981f08496c9d413602 (patch)
tree3b9ead25b30647974fecc3034ff43a9c10d99c2f /org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
parentb5c594216ba1a462796e5e4d8d929062db143768 (diff)
downloadjgit-b2ee9cfbc3b757dc7e7896981f08496c9d413602.tar.gz
jgit-b2ee9cfbc3b757dc7e7896981f08496c9d413602.zip
Enhance fsTick() to use filesystem timer resolution
RepositoryTestCase.fsTick() was was waiting 64, 128, 256, ... milliseconds until it detected that the filesystem timer has ticked. Make use of the filesystemtimer resolution information in FS to sleep a fraction of the filesystem timer resolution. That raises probability to wake up shortly after the filesystem timer has ticked. Change-Id: Ibcc38576e42ece13b2fd4423a29c459eed167a69
Diffstat (limited to 'org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
index 5eddb3d08c..987f923b0e 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
@@ -349,7 +349,8 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
* younger modification timestamp than the modification timestamp of the
* given file. This is done by touching a temporary file, reading the
* lastmodified attribute and, if needed, sleeping. After sleeping this loop
- * starts again until the filesystem timer has advanced enough.
+ * starts again until the filesystem timer has advanced enough. The
+ * temporary file will be created as a sibling of lastFile.
*
* @param lastFile
* the file on which we want to wait until the filesystem timer
@@ -362,18 +363,25 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
*/
public static long fsTick(File lastFile) throws InterruptedException,
IOException {
- long sleepTime = 64;
+ File tmp;
FS fs = FS.DETECTED;
- if (lastFile != null && !fs.exists(lastFile))
- throw new FileNotFoundException(lastFile.getPath());
- File tmp = File.createTempFile("FileTreeIteratorWithTimeControl", null);
+ if (lastFile == null) {
+ lastFile = tmp = File
+ .createTempFile("fsTickTmpFile", null);
+ } else {
+ if (!fs.exists(lastFile)) {
+ throw new FileNotFoundException(lastFile.getPath());
+ }
+ tmp = File.createTempFile("fsTickTmpFile", null,
+ lastFile.getParentFile());
+ }
+ long res = FS.getFsTimerResolution(tmp.toPath()).toMillis();
+ long sleepTime = res / 10;
try {
- long startTime = (lastFile == null) ? fs.lastModified(tmp) : fs
- .lastModified(lastFile);
+ long startTime = fs.lastModified(lastFile);
long actTime = fs.lastModified(tmp);
while (actTime <= startTime) {
Thread.sleep(sleepTime);
- sleepTime *= 2;
FileUtils.touch(tmp.toPath());
actTime = fs.lastModified(tmp);
}