ReplicationIT: Retry/timeout on assertion of replication tasks count
When running the tests repeatedly [1], flakiness is observed in the
assertion about the expected count of replication tasks. Intermittently
it fails due to the actual value being less than expected [2, 3].
Wrapping the assertion in a retry with timeout fixes this flakiness.
[1] bazel test --runs_per_test=24 plugins/replication:replication_tests
[2] value of : listReplicationTasks(...).size()
expected : 4
but was : 2
[3] value of : listReplicationTasks(...).size()
expected : 4
but was : 3
Bug: Issue 11843
Change-Id: I13b05f0dcc0ec95af9e84522231a291f1a785f90
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 19269f0..c4d1b3e 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java
@@ -98,7 +98,7 @@
Project.NameKey sourceProject = createTestProject("foo");
- assertThat(listReplicationTasks("refs/meta/config")).hasSize(1);
+ assertReplicationTaskCount("refs/meta/config", 1);
waitUntil(() -> projectExists(Project.nameKey(sourceProject + "replica.git")));
@@ -117,7 +117,7 @@
RevCommit sourceCommit = pushResult.getCommit();
String sourceRef = pushResult.getPatchSet().refName();
- assertThat(listReplicationTasks("refs/changes/\\d*/\\d*/\\d*")).hasSize(1);
+ assertReplicationTaskCount("refs/changes/\\d*/\\d*/\\d*", 1);
try (Repository repo = repoManager.openRepository(targetProject)) {
waitUntil(() -> checkedGetRef(repo, sourceRef) != null);
@@ -140,7 +140,7 @@
input.revision = master;
gApi.projects().name(project.get()).branch(newBranch).create(input);
- assertThat(listReplicationTasks("refs/heads/(mybranch|master)")).hasSize(2);
+ assertReplicationTaskCount("refs/heads/(mybranch|master)", 2);
try (Repository repo = repoManager.openRepository(targetProject);
Repository sourceRepo = repoManager.openRepository(project)) {
@@ -166,7 +166,7 @@
RevCommit sourceCommit = pushResult.getCommit();
String sourceRef = pushResult.getPatchSet().refName();
- assertThat(listReplicationTasks("refs/changes/\\d*/\\d*/\\d*")).hasSize(2);
+ assertReplicationTaskCount("refs/changes/\\d*/\\d*/\\d*", 2);
try (Repository repo1 = repoManager.openRepository(targetProject1);
Repository repo2 = repoManager.openRepository(targetProject2)) {
@@ -198,7 +198,7 @@
createChange();
- assertThat(listReplicationTasks("refs/changes/\\d*/\\d*/\\d*")).hasSize(4);
+ assertReplicationTaskCount("refs/changes/\\d*/\\d*/\\d*", 4);
setReplicationDestination("foo1", replicaSuffixes, ALL_PROJECTS);
setReplicationDestination("foo2", replicaSuffixes, ALL_PROJECTS);
@@ -234,7 +234,7 @@
.getInstance(ReplicationQueue.class)
.scheduleFullSync(project, null, new ReplicationState(pushResultProcessing), true);
- assertThat(listReplicationTasks(".*all.*")).hasSize(1);
+ assertReplicationTaskCount(".*all.*", 1);
}
@Test
@@ -397,6 +397,10 @@
return projectOperations.newProject().name(name).create();
}
+ private void assertReplicationTaskCount(String refRegex, int expectedCount) throws Exception {
+ waitUntil(() -> listReplicationTasks(refRegex).size() == expectedCount);
+ }
+
private List<ReplicateRefUpdate> listReplicationTasks(String refRegex) {
Pattern refmaskPattern = Pattern.compile(refRegex);
return tasksStorage.listWaiting().stream()