Audit: sandbox integration tests for removing flakiness
When running audit integration tests, the individual executions need
to be sandboxed to avoid parallel execution to interfere between each
other and make test failing intermittently.
Change-Id: I11178bfd789ba4f9516b38e22e489a4cd521e254
diff --git a/java/com/google/gerrit/acceptance/AbstractDaemonTest.java b/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
index d77e1a1..5155e6c 100644
--- a/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
+++ b/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
@@ -125,7 +125,6 @@
import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.FakeEmailSender;
import com.google.gerrit.testing.FakeEmailSender.Message;
-import com.google.gerrit.testing.FakeGroupAuditService;
import com.google.gerrit.testing.SshMode;
import com.google.gson.Gson;
import com.google.gwtorm.server.OrmException;
@@ -242,7 +241,6 @@
@Inject protected ChangeNoteUtil changeNoteUtil;
@Inject protected ChangeResource.Factory changeResourceFactory;
@Inject protected FakeEmailSender sender;
- @Inject protected FakeGroupAuditService auditService;
@Inject protected GerritApi gApi;
@Inject protected GitRepositoryManager repoManager;
@Inject protected GroupBackend groupBackend;
diff --git a/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletIT.java b/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletIT.java
index 90f4134..26ace25 100644
--- a/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletIT.java
+++ b/javatests/com/google/gerrit/acceptance/git/GitOverHttpServletIT.java
@@ -16,8 +16,10 @@
import static com.google.common.truth.Truth.assertThat;
+import com.google.gerrit.acceptance.Sandboxed;
import com.google.gerrit.server.AuditEvent;
import com.google.gerrit.server.audit.HttpAuditEvent;
+import com.google.gerrit.testing.FakeGroupAuditService;
import java.util.Collections;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.transport.CredentialsProvider;
@@ -34,18 +36,19 @@
CredentialsProvider.setDefault(
new UsernamePasswordCredentialsProvider(admin.username, admin.httpPassword));
selectProtocol(AbstractPushForReview.Protocol.HTTP);
- auditService.clearEvents();
}
@Test
+ @Sandboxed
public void receivePackAuditEventLog() throws Exception {
+ FakeGroupAuditService auditService = clearAuditService();
testRepo
.git()
.push()
.setRemote("origin")
.setRefSpecs(new RefSpec("HEAD:refs/for/master"))
.call();
- waitForAudit();
+ waitForAudit(auditService);
// Git smart protocol makes two requests:
// https://github.com/git/git/blob/master/Documentation/technical/http-protocol.txt
@@ -59,9 +62,11 @@
}
@Test
+ @Sandboxed
public void uploadPackAuditEventLog() throws Exception {
+ FakeGroupAuditService auditService = clearAuditService();
testRepo.git().fetch().call();
- waitForAudit();
+ waitForAudit(auditService);
assertThat(auditService.auditEvents.size()).isEqualTo(1);
@@ -73,7 +78,14 @@
assertThat(((HttpAuditEvent) e).httpStatus).isEqualTo(HttpServletResponse.SC_OK);
}
- private void waitForAudit() throws InterruptedException {
+ private FakeGroupAuditService clearAuditService() {
+ FakeGroupAuditService auditService =
+ server.getTestInjector().getInstance(FakeGroupAuditService.class);
+ auditService.clearEvents();
+ return auditService;
+ }
+
+ private void waitForAudit(FakeGroupAuditService auditService) throws InterruptedException {
synchronized (auditService.auditEvents) {
auditService.auditEvents.wait(AUDIT_EVENT_TIMEOUT);
}