ChangeBundle: Ignore lastUpdatedOn if bundle has no entities

I found a few changes in our dataset where the lastUpdatedOn timestamp
of the Change was later than any other entity, but no other fields
differed so no FinalUpdatesEvent was added to the list. This is in
theory possible, for example if the change state changed multiple
times but ended up in the original state. There's not much we can do
on the NoteDb side if we don't want to add a dummy event just to
update the timestamp, which we don't, really.

Just allow NoteDb lastUpdatedOn timestamps to match either the
timestamp on the Change, or the latest timestamp among all entities
other than the Change itself.

Change-Id: I3d933b878747fae76c5509107e6cedbd9cd5115a
This commit is contained in:
Dave Borowitz
2016-05-04 13:15:49 -04:00
parent 1f0e2df353
commit e46af3e2b8
2 changed files with 39 additions and 3 deletions

View File

@@ -293,6 +293,41 @@ public class ChangeBundleTest {
assertNoDiffs(b1, b2);
}
@Test
public void diffChangesIgnoresChangeTimestampIfAnyOtherEntitiesExist() {
Change c1 = TestChanges.newChange(
new Project.NameKey("project"), new Account.Id(100));
PatchSetApproval a = new PatchSetApproval(
new PatchSetApproval.Key(
c1.currentPatchSetId(), accountId, new LabelId("Code-Review")),
(short) 1,
TimeUtil.nowTs());
c1.setLastUpdatedOn(a.getGranted());
Change c2 = clone(c1);
c2.setLastUpdatedOn(TimeUtil.nowTs());
// ReviewDb has later lastUpdatedOn timestamp than NoteDb, allowed since
// NoteDb matches the latest timestamp of a non-Change entity.
ChangeBundle b1 = new ChangeBundle(c2, messages(), patchSets(),
approvals(a), comments(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c1, messages(), patchSets(),
approvals(a), comments(), NOTE_DB);
assertThat(b1.getChange().getLastUpdatedOn())
.isGreaterThan(b2.getChange().getLastUpdatedOn());
assertNoDiffs(b1, b2);
// Timestamps must actually match if Change is the only entity.
b1 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(),
REVIEW_DB);
b2 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(),
NOTE_DB);
assertDiffs(b1, b2,
"effective last updated time differs for Change.Id " + c1.getId()
+ " in NoteDb vs. ReviewDb:"
+ " {2009-09-30 17:00:06.0} != {2009-09-30 17:00:12.0}");
}
@Test
public void diffChangesAllowsReviewDbSubjectToBePrefixOfNoteDbSubject()
throws Exception {