SubmitByMergeAlwaysIT: Test ref-updated event for multiple changes
Update the submitMultipleChanges test to confirm that only a single ref-updated event is emitted when multiple changes are submitted by merge. Change-Id: I63f7a14cf425578a2f2a82036b95eecf87737b02
This commit is contained in:
@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.eclipse.jgit.lib.Constants.R_HEADS;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
@@ -94,6 +95,15 @@ public class EventRecorder {
|
||||
return (RefUpdatedEvent) e;
|
||||
}
|
||||
|
||||
public ImmutableList<RefEvent> getRefUpdates(String project, String refName,
|
||||
int expectedSize) {
|
||||
String key = key(RefUpdatedEvent.TYPE, project, refName);
|
||||
assertThat(recordedEvents).containsKey(key);
|
||||
Collection<RefEvent> events = recordedEvents.get(key);
|
||||
assertThat(events).hasSize(expectedSize);
|
||||
return ImmutableList.copyOf(events);
|
||||
}
|
||||
|
||||
public ChangeMergedEvent getOneChangeMerged(String project, String branch,
|
||||
final String changeNumber) throws Exception {
|
||||
String key = key(ChangeMergedEvent.TYPE, project,
|
||||
|
||||
@@ -18,6 +18,9 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.server.data.RefUpdateAttribute;
|
||||
import com.google.gerrit.server.events.RefEvent;
|
||||
import com.google.gerrit.server.events.RefUpdatedEvent;
|
||||
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Test;
|
||||
@@ -49,31 +52,53 @@ public class SubmitByMergeAlwaysIT extends AbstractSubmitByMerge {
|
||||
public void submitMultipleChanges() throws Exception {
|
||||
RevCommit initialHead = getRemoteHead();
|
||||
|
||||
testRepo.reset(initialHead);
|
||||
// Submit a change so that the remote head advances
|
||||
PushOneCommit.Result change2 = createChange("Change 2", "b", "b");
|
||||
submit(change2.getChangeId());
|
||||
|
||||
testRepo.reset(initialHead);
|
||||
// The remote head should now be a merge of the previous head
|
||||
// and "Change 2"
|
||||
RevCommit headAfterFirstSubmit = getRemoteLog().get(0);
|
||||
assertThat(headAfterFirstSubmit.getParent(1).getShortMessage()).isEqualTo(
|
||||
change2.getCommit().getShortMessage());
|
||||
assertThat(headAfterFirstSubmit.getParent(0).getShortMessage()).isEqualTo(
|
||||
initialHead.getShortMessage());
|
||||
assertThat(headAfterFirstSubmit.getParent(0).getId()).isEqualTo(
|
||||
initialHead.getId());
|
||||
|
||||
// Submit two changes at the same time
|
||||
PushOneCommit.Result change3 = createChange("Change 3", "c", "c");
|
||||
|
||||
testRepo.reset(initialHead);
|
||||
PushOneCommit.Result change4 = createChange("Change 4", "d", "d");
|
||||
|
||||
approve(change2.getChangeId());
|
||||
approve(change3.getChangeId());
|
||||
submit(change4.getChangeId());
|
||||
|
||||
List<RevCommit> log = getRemoteLog();
|
||||
RevCommit tip = log.get(0);
|
||||
assertThat(tip.getParent(1).getShortMessage()).isEqualTo(
|
||||
// Submitting change 4 should result in change 3 also being submitted
|
||||
assertMerged(change3.getChangeId());
|
||||
|
||||
// The remote head should now be a merge of the new head after
|
||||
// the previous submit, and "Change 4".
|
||||
RevCommit headAfterSecondSubmit = getRemoteLog().get(0);
|
||||
assertThat(headAfterSecondSubmit.getParent(1).getShortMessage()).isEqualTo(
|
||||
change4.getCommit().getShortMessage());
|
||||
assertThat(tip.getParent(0).getShortMessage()).isEqualTo(
|
||||
initialHead.getShortMessage());
|
||||
assertThat(tip.getParent(0).getId()).isEqualTo(initialHead.getId());
|
||||
assertThat(headAfterSecondSubmit.getParent(0).getShortMessage()).isEqualTo(
|
||||
headAfterFirstSubmit.getShortMessage());
|
||||
assertThat(headAfterSecondSubmit.getParent(0).getId()).isEqualTo(
|
||||
headAfterFirstSubmit.getId());
|
||||
assertPersonEquals(admin.getIdent(), headAfterSecondSubmit.getAuthorIdent());
|
||||
assertPersonEquals(serverIdent.get(),
|
||||
headAfterSecondSubmit.getCommitterIdent());
|
||||
|
||||
assertPersonEquals(admin.getIdent(), tip.getAuthorIdent());
|
||||
assertPersonEquals(serverIdent.get(), tip.getCommitterIdent());
|
||||
// The two submit operations should have resulted in two ref-update events
|
||||
List<RefEvent> refUpdates = eventRecorder.getRefUpdates(
|
||||
project.get(), "refs/heads/master", 2);
|
||||
|
||||
assertNew(change2.getChangeId());
|
||||
assertNew(change3.getChangeId());
|
||||
RefUpdateAttribute refUpdate =
|
||||
((RefUpdatedEvent)(refUpdates.get(0))).refUpdate.get();
|
||||
assertThat(refUpdate.oldRev).isEqualTo(initialHead.name());
|
||||
assertThat(refUpdate.newRev).isEqualTo(headAfterFirstSubmit.name());
|
||||
|
||||
refUpdate = ((RefUpdatedEvent)(refUpdates.get(1))).refUpdate.get();
|
||||
assertThat(refUpdate.oldRev).isEqualTo(headAfterFirstSubmit.name());
|
||||
assertThat(refUpdate.newRev).isEqualTo(headAfterSecondSubmit.name());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user