From 7f92a70fb3a5b7e91e5d370098fa65f6c8f35efa Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sun, 11 Aug 2019 02:43:02 +0200 Subject: [PATCH] Avoid setup and saving FileStoreAttributes compete for ~/.gitconfig lock FS determines FileStore attributes in a background thread and tries to save the results to the global git configuration. This competed with LocalDiskRepositoryTestCase#setup trying to save changes to the same file requiring the same lock. This frequently led to one of the threads failing to acquire the lock. Fix this by first initiating determination of FileStore attributes which then uses a MockSystemReader not using a userConfig stored to disk which avoids this race for the lock. Change-Id: I30fcd96bc15100f8ef9b2a9eb3320bb5ace97c67 Signed-off-by: Matthias Sohn --- .../jgit/junit/LocalDiskRepositoryTestCase.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index cce83c00b..f8f0c18cb 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -130,6 +130,13 @@ public abstract class LocalDiskRepositoryTestCase { mockSystemReader = new MockSystemReader(); SystemReader.setInstance(mockSystemReader); + + // Measure timer resolution before the test to avoid time critical tests + // are affected by time needed for measurement. + // The MockSystemReader must be configured first since we need to use + // the same one here + FS.getFileStoreAttributes(tmp.toPath().getParent()); + mockSystemReader.userGitConfig = new FileBasedConfig(new File(tmp, "usergitconfig"), FS.DETECTED); // We have to set autoDetach to false for tests, because tests expect to be able @@ -140,12 +147,6 @@ public abstract class LocalDiskRepositoryTestCase { mockSystemReader.userGitConfig.save(); ceilTestDirectories(getCeilings()); - // Measure timer resolution before the test to avoid time critical tests - // are affected by time needed for measurement. - // The MockSystemReader must be configured first since we need to use - // the same one here - FS.getFileStoreAttributes(tmp.toPath().getParent()); - author = new PersonIdent("J. Author", "jauthor@example.com"); committer = new PersonIdent("J. Committer", "jcommitter@example.com");