uploadPackAuditEventLog: Avoid commit timestamp mismatch

JGit's TestRepository instance uses a mocked system reader with a mocked
time source:

  now = Aug 15 20:12:58 GMT-03:30 2009

That's why the new upstream commit has a commit time 11 years in the
past. However, when a new repository is created, an empty commit is
created per default without using the mocked system reader. When second
commit is created, using TestRepository, then we have the following
situation:

root commit   timestamp: 1611269860
second commit timestamp: 1250379779

Until now we don't really care, but in the recent JGit version git wire
protocol v2 is used per default for fetching. When trying to upgrade to
this new JGit version, we supposed to change the number of requests
required to fetch new commit from remote repository from 2 to 3.

However due to timestamp skew between root commit and second commit 4
requests are required. Even though, the want commit is present in the
repository, it's not found in UploadPack.wantSatisfied() method because
of commit TimeRev filter:

  if (oldestTime != 0)
      walk.setRevFilter(CommitTimeRevFilter.after(oldestTime * 1000L));

Because the common base commit timestamp is older than the second
commit, commit TimeRev filter prevents the want commit to be found.
As the consequence the fetch command isn't finishing with three requests
and an additional request is required.

To rectify, skip empty commit during project creation, and create
common commit using TestRepository instead. That way the same mocked
system reader is used for both commits.

This is the fix for JGit update change: I00fd18587c.

Change-Id: Idd60394b8d3453c3b61fec292867f28a5532aa8b
diff --git a/javatests/com/google/gerrit/acceptance/git/AbstractGitOverHttpServlet.java b/javatests/com/google/gerrit/acceptance/git/AbstractGitOverHttpServlet.java
index 7f01fb9..a22759f 100644
--- a/javatests/com/google/gerrit/acceptance/git/AbstractGitOverHttpServlet.java
+++ b/javatests/com/google/gerrit/acceptance/git/AbstractGitOverHttpServlet.java
@@ -19,6 +19,7 @@
 import com.google.common.collect.ImmutableList;
 import com.google.gerrit.acceptance.FakeGroupAuditService;
 import com.google.gerrit.acceptance.Sandboxed;
+import com.google.gerrit.acceptance.TestProjectInput;
 import com.google.gerrit.entities.Account;
 import com.google.gerrit.pgm.http.jetty.JettyServer;
 import com.google.gerrit.server.audit.HttpAuditEvent;
@@ -80,6 +81,7 @@
   }
 
   @Test
+  @TestProjectInput(createEmptyCommit = false)
   public void authenticatedUploadPackAuditEventLog() throws Exception {
     String remote = "authenticated";
     Config cfg = testRepo.git().getRepository().getConfig();
@@ -92,6 +94,7 @@
   }
 
   @Test
+  @TestProjectInput(createEmptyCommit = false)
   public void anonymousUploadPackAuditEventLog() throws Exception {
     String remote = "anonymous";
     Config cfg = testRepo.git().getRepository().getConfig();
@@ -110,16 +113,18 @@
    */
   private void uploadPackAuditEventLog(String remote, Optional<Account.Id> accountId)
       throws Exception {
+    // Make a server-side change to have a common base.
+    createCommit("foo");
+    testRepo.git().fetch().call();
+
+    // Make a server-side change so we have something to fetch.
+    createCommit("bar");
+
     auditService.drainHttpAuditEvents();
-    // testRepo is already a clone. Make a server-side change so we have something to fetch.
-    try (Repository repo = repoManager.openRepository(project);
-        TestRepository<?> testRepo = new TestRepository<>(repo)) {
-      testRepo.branch("master").commit().create();
-    }
     testRepo.git().fetch().setRemote(remote).call();
 
     ImmutableList<HttpAuditEvent> auditEvents = auditService.drainHttpAuditEvents();
-    assertThat(auditEvents).hasSize(4);
+    assertThat(auditEvents).hasSize(3);
 
     // Protocol V2 Capability advertisement
     // https://git-scm.com/docs/protocol-v2#_capability_advertisement
@@ -147,11 +152,13 @@
     assertThat(uploadPackFetch.what).endsWith("/git-upload-pack");
     assertThat(uploadPackFetch.params).isEmpty();
     assertThat(uploadPackFetch.httpStatus).isEqualTo(HttpServletResponse.SC_OK);
-    HttpAuditEvent uploadPackDone = auditEvents.get(3);
-
-    assertThat(uploadPackDone.what).endsWith("/git-upload-pack");
-    assertThat(uploadPackDone.params).isEmpty();
-    assertThat(uploadPackDone.httpStatus).isEqualTo(HttpServletResponse.SC_OK);
     assertThat(jettyServer.numActiveSessions()).isEqualTo(0);
   }
+
+  private void createCommit(String message) throws Exception {
+    try (Repository repo = repoManager.openRepository(project);
+        TestRepository<Repository> tr = new TestRepository<>(repo)) {
+      tr.branch("master").commit().message(message).create();
+    }
+  }
 }