From 8d43def49fab4de78f46270f32ccd8693931a506 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 18 Dec 2019 01:49:32 +0100 Subject: [PATCH 1/4] StandaloneSiteTest: Ignore jgit config Override SystemReader to return empty file jgit config. This makes IT tests independent of the configuration of the system they are running on. In addition it avoids exceptions due to bazel sandboxing access to the user's home directory where the jgit config wants to persist measured file timestamp resolutions. Change-Id: I6c6717b3d7bc98ec45c204e9043bab4315aae551 --- java/com/google/gerrit/acceptance/StandaloneSiteTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/java/com/google/gerrit/acceptance/StandaloneSiteTest.java b/java/com/google/gerrit/acceptance/StandaloneSiteTest.java index a095daaf20..1d6f51f8f6 100644 --- a/java/com/google/gerrit/acceptance/StandaloneSiteTest.java +++ b/java/com/google/gerrit/acceptance/StandaloneSiteTest.java @@ -143,6 +143,11 @@ public abstract class StandaloneSiteTest { SystemReader oldSystemReader = SystemReader.getInstance(); SystemReader.setInstance( new DelegateSystemReader(oldSystemReader) { + @Override + public FileBasedConfig openJGitConfig(Config parent, FS fs) { + return new FileBasedConfig(parent, new File(tempDir, "jgit.config"), FS.detect()); + } + @Override public FileBasedConfig openUserConfig(Config parent, FS fs) { return new FileBasedConfig(parent, new File(tempDir, "user.config"), FS.detect()); From 934b58ee219223abbfeb3d09cda2b265e4cc8324 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 25 Dec 2019 16:13:22 +0100 Subject: [PATCH 2/4] AbstractDaemonTest: use fake SystemReader Use a fake SystemReader providing empty system, user and jgit configurations to isolate tests from real git configurations present on the machine the tests run on. Change-Id: I4dc9c4849c43c5c440626fa53d965b7a2dde40d7 --- .../gerrit/acceptance/AbstractDaemonTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/java/com/google/gerrit/acceptance/AbstractDaemonTest.java b/java/com/google/gerrit/acceptance/AbstractDaemonTest.java index 7edb43a845..86614b3e8f 100644 --- a/java/com/google/gerrit/acceptance/AbstractDaemonTest.java +++ b/java/com/google/gerrit/acceptance/AbstractDaemonTest.java @@ -124,6 +124,7 @@ import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.query.change.InternalChangeQuery; import com.google.gerrit.server.restapi.change.Revisions; import com.google.gerrit.server.update.BatchUpdate; +import com.google.gerrit.server.util.git.DelegateSystemReader; import com.google.gerrit.testing.ConfigSuite; import com.google.gerrit.testing.FakeEmailSender; import com.google.gerrit.testing.FakeEmailSender.Message; @@ -135,6 +136,7 @@ import com.google.inject.Module; import com.google.inject.Provider; import com.jcraft.jsch.KeyPair; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -170,11 +172,14 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevSort; import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.transport.FetchResult; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.TransportBundleStream; import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.util.SystemReader; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -289,6 +294,7 @@ public abstract class AbstractDaemonTest { private ProjectResetter resetter; private List toClose; private String systemTimeZone; + private SystemReader oldSystemReader; @Before public void clearSender() { @@ -385,6 +391,10 @@ public abstract class AbstractDaemonTest { } protected void beforeTest(Description description) throws Exception { + // SystemReader must be overridden before creating any repos, since they read the user/system + // configs at initialization time, and are then stored in the RepositoryCache forever. + oldSystemReader = setFakeSystemReader(temporaryFolder.getRoot()); + this.description = description; GerritServer.Description classDesc = GerritServer.Description.forTestClass(description, configName); @@ -447,6 +457,28 @@ public abstract class AbstractDaemonTest { methodDesc.useSystemTime(), methodDesc.useClockStep(), methodDesc.useTimezone()); } + private static SystemReader setFakeSystemReader(File tempDir) { + SystemReader oldSystemReader = SystemReader.getInstance(); + SystemReader.setInstance( + new DelegateSystemReader(oldSystemReader) { + @Override + public FileBasedConfig openJGitConfig(Config parent, FS fs) { + return new FileBasedConfig(parent, new File(tempDir, "jgit.config"), FS.detect()); + } + + @Override + public FileBasedConfig openUserConfig(Config parent, FS fs) { + return new FileBasedConfig(parent, new File(tempDir, "user.config"), FS.detect()); + } + + @Override + public FileBasedConfig openSystemConfig(Config parent, FS fs) { + return new FileBasedConfig(parent, new File(tempDir, "system.config"), FS.detect()); + } + }); + return oldSystemReader; + } + private void setTimeSettings( boolean useSystemTime, @Nullable UseClockStep useClockStep, @@ -602,6 +634,8 @@ public abstract class AbstractDaemonTest { server.close(); server = null; } + SystemReader.setInstance(oldSystemReader); + oldSystemReader = null; } protected void closeSsh() { From fad0061928a407744e8395eb8fe297846f022348 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Thu, 26 Dec 2019 10:46:22 +0100 Subject: [PATCH 3/4] Bazel: Remove suppression of JSC_REFERENCE_BEFORE_DECLARE Change-Id: I10c99e9f6a9bcabb7c55a92162a452d5424e7b97 --- polygerrit-ui/app/rules.bzl | 3 --- 1 file changed, 3 deletions(-) diff --git a/polygerrit-ui/app/rules.bzl b/polygerrit-ui/app/rules.bzl index e1304e6aeb..4c16c914e9 100644 --- a/polygerrit-ui/app/rules.bzl +++ b/polygerrit-ui/app/rules.bzl @@ -21,8 +21,6 @@ def polygerrit_bundle(name, srcs, outs, app): deps = [name + "_closure_lib"], ) - # TODO(davido): Remove JSC_REFERENCE_BEFORE_DECLARE when this is fixed upstream: - # https://github.com/Polymer/polymer-resin/issues/7 closure_js_library( name = name + "_closure_lib", srcs = [appName + ".js"], @@ -31,7 +29,6 @@ def polygerrit_bundle(name, srcs, outs, app): # and remove this supression suppress = [ "JSC_JSDOC_MISSING_TYPE_WARNING", - "JSC_REFERENCE_BEFORE_DECLARE", "JSC_UNNECESSARY_ESCAPE", "JSC_UNUSED_LOCAL_ASSIGNMENT", ], From 6d575990171696f3b1360d1882668f138b5dbaa3 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Thu, 26 Dec 2019 13:03:47 +0100 Subject: [PATCH 4/4] Bazel: Remove suppression of JSC_UNUSED_LOCAL_ASSIGNMENT Change-Id: I4c17bed7fabd4f93562e31a0459e123cdc6ebeac --- polygerrit-ui/app/rules.bzl | 1 - 1 file changed, 1 deletion(-) diff --git a/polygerrit-ui/app/rules.bzl b/polygerrit-ui/app/rules.bzl index f01b368f4b..93c662aa55 100644 --- a/polygerrit-ui/app/rules.bzl +++ b/polygerrit-ui/app/rules.bzl @@ -31,7 +31,6 @@ def polygerrit_bundle(name, srcs, outs, app): suppress = [ "JSC_JSDOC_MISSING_TYPE_WARNING", "JSC_UNNECESSARY_ESCAPE", - "JSC_UNUSED_LOCAL_ASSIGNMENT", ], deps = [ "//lib/polymer_externs:polymer_closure",