Fix ApplyObjectIT flaky test For some builds `ApplyObjectIT.shouldApplyRefMetaObject` test throws `MissingParentObjectException`. Align with other tests the way how this test reads revision data to avoid flaky results. Bug: Issue 289961082 Change-Id: I1083818ed15adf9d6322f77b1be846b53fc5dbbe
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/fetch/ApplyObjectIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/fetch/ApplyObjectIT.java index 161830b..c75d32a 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/fetch/ApplyObjectIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/fetch/ApplyObjectIT.java
@@ -77,12 +77,15 @@ Result pushResult = createChange(); String refName = RefNames.changeMetaRef(pushResult.getChange().getId()); - Optional<RevisionData> revisionData = - reader.read( - Project.nameKey(testRepoProjectName), pushResult.getCommit().toObjectId(), refName, 0); - RefSpec refSpec = new RefSpec(refName); - objectUnderTest.apply(project, refSpec, toArray(revisionData)); + Optional<RevisionData> revisionData; + NameKey testRepoKey = Project.nameKey(testRepoProjectName); + + try (Repository repo = repoManager.openRepository(testRepoKey)) { + revisionData = reader.read(testRepoKey, repo.exactRef(refName).getObjectId(), refName, 0); + objectUnderTest.apply(project, refSpec, toArray(revisionData)); + } + try (Repository repo = repoManager.openRepository(project); TestRepository<Repository> testRepo = new TestRepository<>(repo); ) { Optional<RevisionData> newRevisionData =