Add a test to cover Distributor pruning feature To test if distributor can prune, we add an event to storage and then delete the waiting task from storage to simulate it being started by another node. We then assert that the project task gets pruned from the work queue by the time the next distribution cycle completes. Change-Id: Ifeed8444986be03bddf443fed94170c8ee5ae72c
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDistributorIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDistributorIT.java index 5674732..5ade68d 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDistributorIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDistributorIT.java
@@ -82,6 +82,21 @@ } } + @Test + public void distributorPrunesTaskFromWorkQueue() throws Exception { + createTestProject(project + "replica"); + setReplicationDestination("foo", "replica", ALL_PROJECTS, Integer.MAX_VALUE); + reloadConfig(); + + String newBranch = "refs/heads/foo_branch"; + createBranch(project, "refs/heads/master", newBranch); + + deleteWaitingReplicationTasks(newBranch); // This simulates the work being started by other node + + assertThat(waitForProjectTaskCount(0, Duration.ofSeconds(TEST_DISTRIBUTION_CYCLE_SECONDS))) + .isTrue(); + } + private List<WorkQueue.Task<?>> getProjectTasks() { return getInstance(WorkQueue.class).getTasks().stream() .filter(t -> t instanceof WorkQueue.ProjectTask)