Fix flaky test in Pull Replication plugin Remove flaky test in FetchActionIT and move it to PullReplicationIT/PullReplicationAsyncIT to test `fetch async in replica` use case Bug: Issue 16338 Change-Id: I870cc27b13eeaf361c355744c3cdbe4986018fcd
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationIT.java index 62f42c3..187af3d 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationIT.java
@@ -397,6 +397,35 @@ }); } + @Test + @GerritConfig(name = "gerrit.instanceId", value = TEST_REPLICATION_REMOTE) + @GerritConfig(name = "container.replica", value = "true") + public void shouldReplicateNewChangeRefToReplica() throws Exception { + testRepo = cloneProject(createTestProject(project + TEST_REPLICATION_SUFFIX)); + + Result pushResult = createChange(); + RevCommit sourceCommit = pushResult.getCommit(); + String sourceRef = pushResult.getPatchSet().refName(); + + ReplicationQueue pullReplicationQueue = getInstance(ReplicationQueue.class); + GitReferenceUpdatedListener.Event event = + new FakeGitReferenceUpdatedEvent( + project, + sourceRef, + ObjectId.zeroId().getName(), + sourceCommit.getId().getName(), + ReceiveCommand.Type.CREATE); + pullReplicationQueue.onGitReferenceUpdated(event); + + try (Repository repo = repoManager.openRepository(project)) { + waitUntil(() -> checkedGetRef(repo, sourceRef) != null); + + Ref targetBranchRef = getRef(repo, sourceRef); + assertThat(targetBranchRef).isNotNull(); + assertThat(targetBranchRef.getObjectId()).isEqualTo(sourceCommit.getId()); + } + } + private Ref getRef(Repository repo, String branchName) throws IOException { return repo.getRefDatabase().exactRef(branchName); }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java index 6691fdf..55ad15c 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java
@@ -66,7 +66,7 @@ httpModule = "com.googlesource.gerrit.plugins.replication.pull.api.HttpModule") public abstract class ActionITBase extends LightweightPluginDaemonTest { protected static final Optional<String> ALL_PROJECTS = Optional.empty(); - protected static final int TEST_REPLICATION_DELAY = 1; + protected static final int TEST_REPLICATION_DELAY = 60; protected static final String TEST_REPLICATION_SUFFIX = "suffix1"; protected static final String TEST_REPLICATION_REMOTE = "remote1";
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java index 440de99..5634b2a 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java
@@ -42,24 +42,6 @@ @Test @GerritConfig(name = "container.replica", value = "true") - public void shouldFetchRefAsyncWhenNodeIsAReplica() throws Exception { - String refName = createRef(); - String sendObjectPayload = - "{\"label\":\"" - + TEST_REPLICATION_REMOTE - + "\", \"ref_name\": \"" - + refName - + "\", \"async\":true}"; - - httpClientFactory - .create(source) - .execute( - withBasicAuthenticationAsAdmin(createRequest(sendObjectPayload)), - assertHttpResponseCode(202)); - } - - @Test - @GerritConfig(name = "container.replica", value = "true") public void shouldFetchRefWhenNodeIsAReplicaAndProjectNameContainsSlash() throws Exception { NameKey projectName = Project.nameKey("test/repo"); String refName = createRef(projectName);