diff options
author | Luca Milanesio <luca.milanesio@gmail.com> | 2020-07-01 22:46:23 +0100 |
---|---|---|
committer | Luca Milanesio <luca.milanesio@gmail.com> | 2020-07-01 22:46:23 +0100 |
commit | a2f3dba7722e68a7ac1ee917c2bf4d59c3c8d80b (patch) | |
tree | 8fca3f5da9bfc8a82c14dd8e9bfd4e2f02dd65e5 | |
parent | fda228c18de9def19fbd50c2d01ebbb42e7c73cc (diff) | |
parent | 1812e0d2ce7e261d90e7c0b726376a6938680786 (diff) |
Merge branch 'stable-3.0' into stable-3.1
* stable-3.0:
Improve readability of shouldFirePendingOnlyToStoredUri test
Fix flakiness in ReplicationIT for pending events firing
Change-Id: I58ce5a03d7b1094ef859c4cd2bd08a3ead00ba30
-rw-r--r-- | src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java | 69 |
1 files changed, 41 insertions, 28 deletions
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 60f55ac..31cd75d 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Optional; import java.util.function.Supplier; import java.util.regex.Pattern; +import java.util.stream.Stream; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; @@ -455,37 +456,25 @@ public class ReplicationIT extends LightweightPluginDaemonTest { Project.NameKey target2 = createTestProject(project + suffix2); String remote1 = "foo1"; String remote2 = "foo2"; - setReplicationDestination(remote1, suffix1, ALL_PROJECTS); - setReplicationDestination(remote2, suffix2, ALL_PROJECTS); + setReplicationDestination(remote1, suffix1, ALL_PROJECTS, Integer.MAX_VALUE, false); + setReplicationDestination(remote2, suffix2, ALL_PROJECTS, Integer.MAX_VALUE, false); reloadConfig(); - Result pushResult = createChange(); - String sourceRef = pushResult.getPatchSet().refName(); - - replicationQueueStop(); + String changeRef = createChange().getPatchSet().refName(); tasksStorage.disableDeleteForTesting(false); - listReplicationTasks("refs/changes/\\d*/\\d*/\\d*").stream() - .filter(task -> remote1.equals(task.remote)) - .forEach(u -> tasksStorage.delete(u)); + changeReplicationTasksForRemote(changeRef, remote1).forEach(tasksStorage::delete); tasksStorage.disableDeleteForTesting(true); - assertThat( - listReplicationTasks("refs/changes/\\d*/\\d*/\\d*").stream() - .filter(task -> remote2.equals(task.remote)) - .collect(toList())) - .hasSize(1); - - assertThat( - listReplicationTasks("refs/changes/\\d*/\\d*/\\d*").stream() - .filter(task -> remote1.equals(task.remote)) - .collect(toList())) - .hasSize(0); + setReplicationDestination(remote1, suffix1, ALL_PROJECTS); + setReplicationDestination(remote2, suffix2, ALL_PROJECTS); + reloadConfig(); - replicationQueueStart(); + assertThat(changeReplicationTasksForRemote(changeRef, remote2).count()).isEqualTo(1); + assertThat(changeReplicationTasksForRemote(changeRef, remote1).count()).isEqualTo(0); - assertThat(isPushCompleted(target2, sourceRef, TEST_TIMEOUT)).isEqualTo(true); - assertThat(isPushCompleted(target1, sourceRef, TEST_TIMEOUT)).isEqualTo(false); + assertThat(isPushCompleted(target2, changeRef, TEST_TIMEOUT)).isEqualTo(true); + assertThat(isPushCompleted(target1, changeRef, TEST_TIMEOUT)).isEqualTo(false); } public boolean isPushCompleted(Project.NameKey project, String ref, Duration timeOut) { @@ -514,30 +503,47 @@ public class ReplicationIT extends LightweightPluginDaemonTest { private void setReplicationDestination( String remoteName, String replicaSuffix, Optional<String> project) throws IOException { - setReplicationDestination(remoteName, Arrays.asList(replicaSuffix), project, false); + setReplicationDestination( + remoteName, Arrays.asList(replicaSuffix), project, TEST_REPLICATION_DELAY, false); } private void setReplicationDestination( String remoteName, String replicaSuffix, Optional<String> project, boolean mirror) throws IOException { - setReplicationDestination(remoteName, Arrays.asList(replicaSuffix), project, mirror); + setReplicationDestination( + remoteName, Arrays.asList(replicaSuffix), project, TEST_REPLICATION_DELAY, mirror); + } + + private void setReplicationDestination( + String remoteName, + String replicaSuffix, + Optional<String> project, + int replicationDelay, + boolean mirror) + throws IOException { + setReplicationDestination( + remoteName, Arrays.asList(replicaSuffix), project, replicationDelay, mirror); } private void setReplicationDestination( String remoteName, List<String> replicaSuffixes, Optional<String> project) throws IOException { - setReplicationDestination(remoteName, replicaSuffixes, project, false); + setReplicationDestination(remoteName, replicaSuffixes, project, TEST_REPLICATION_DELAY, false); } private void setReplicationDestination( - String remoteName, List<String> replicaSuffixes, Optional<String> project, boolean mirror) + String remoteName, + List<String> replicaSuffixes, + Optional<String> project, + int replicationDelay, + boolean mirror) throws IOException { List<String> replicaUrls = replicaSuffixes.stream() .map(suffix -> gitPath.resolve("${name}" + suffix + ".git").toString()) .collect(toList()); config.setStringList("remote", remoteName, "url", replicaUrls); - config.setInt("remote", remoteName, "replicationDelay", TEST_REPLICATION_DELAY); + config.setInt("remote", remoteName, "replicationDelay", replicationDelay); config.setInt("remote", remoteName, "replicationRetry", TEST_REPLICATION_RETRY); config.setBoolean("remote", remoteName, "mirror", mirror); project.ifPresent(prj -> config.setString("remote", remoteName, "projects", prj)); @@ -583,6 +589,13 @@ public class ReplicationIT extends LightweightPluginDaemonTest { return plugin.getSysInjector().getInstance(classObj); } + private Stream<ReplicateRefUpdate> changeReplicationTasksForRemote( + String changeRef, String remote) { + return tasksStorage.list().stream() + .filter(task -> changeRef.equals(task.ref)) + .filter(task -> remote.equals(task.remote)); + } + private Project.NameKey createTestProject(String name) throws Exception { return projectOperations.newProject().name(name).create(); } |