ReplicationIT: Add a test that HEAD update is replicated Change-Id: I140a63933fe50bc6d5ec109fe6d46a2371a89f1e
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java index a29d151..1381c99 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
@@ -38,6 +38,7 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; +import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; @@ -187,6 +188,28 @@ assertThat(storagePath.toFile().list()).hasLength(4); } + @Test + public void shouldReplicateHeadUpdate() throws Exception { + setReplicationDestination("foo", "replica", ALL_PROJECTS); + reloadConfig(); + + Project.NameKey targetProject = createProject("projectreplica"); + String newHead = "refs/heads/newhead"; + String master = "refs/heads/master"; + BranchInput input = new BranchInput(); + input.revision = master; + gApi.projects().name(project.get()).branch(newHead).create(input); + gApi.projects().name(project.get()).head(newHead); + + try (Repository repo = repoManager.openRepository(targetProject)) { + waitUntil(() -> checkedGetRef(repo, newHead) != null); + + Ref targetProjectHead = getRef(repo, Constants.HEAD); + assertThat(targetProjectHead).isNotNull(); + assertThat(targetProjectHead.getTarget().getName()).isEqualTo(newHead); + } + } + private Ref getRef(Repository repo, String branchName) throws IOException { return repo.getRefDatabase().exactRef(branchName); }