gossip: crds::test::test_update_timestamp: Remove hash comparison (#29567)

It was not immediately clear why the second `CrdsValue` insertion in the
test must always succeed.  Turns out the test was relying on hash values
having a specific relationship.  It is confusing to someone not deeply
familiar with the test.

As overwrite based on the hash value is not part of the behavior that we
consider valuable, we just remove that check.

Unified assertion between two checks into one.
This commit is contained in:
Illia Bobyr 2023-01-12 00:19:44 -08:00 committed by GitHub
parent a08124e7bb
commit e410d021ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 24 deletions

View File

@ -791,41 +791,38 @@ mod tests {
#[test]
fn test_update_timestamp() {
let mut crds = Crds::default();
let val = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::new_localhost(
&Pubkey::default(),
0,
)));
let val1 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&Pubkey::default(), 0),
));
let val1_hash = hash(&serialize(&val1).unwrap());
assert_eq!(
crds.insert(val.clone(), 0, GossipRoute::LocalMessage),
crds.insert(val1.clone(), 0, GossipRoute::LocalMessage),
Ok(())
);
assert_eq!(crds.table[&val.label()].ordinal, 0);
assert_eq!(crds.table[&val1.label()].local_timestamp, 0);
assert_eq!(crds.table[&val1.label()].ordinal, 0);
let val2 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ContactInfo::default()));
let value_hash = hash(&serialize(&val2).unwrap());
assert_eq!(val2.label().pubkey(), val.label().pubkey());
// `val2` is expected to overwrite `val1` based on the `wallclock` value.
let val2 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(
ContactInfo::new_localhost(&Pubkey::default(), 1),
));
assert_eq!(val2.label().pubkey(), val1.label().pubkey());
assert_eq!(
crds.insert(val2.clone(), 0, GossipRoute::LocalMessage),
crds.insert(val2.clone(), 1, GossipRoute::LocalMessage),
Ok(())
);
assert_eq!(*crds.purged.back().unwrap(), (val1_hash, 1));
crds.update_record_timestamp(&val.label().pubkey(), 2);
assert_eq!(crds.table[&val.label()].local_timestamp, 2);
assert_eq!(crds.table[&val.label()].ordinal, 1);
assert_eq!(crds.table[&val2.label()].local_timestamp, 1);
assert_eq!(crds.table[&val2.label()].ordinal, 1);
crds.update_record_timestamp(&val2.label().pubkey(), 2);
assert_eq!(crds.table[&val2.label()].local_timestamp, 2);
assert_eq!(crds.table[&val2.label()].ordinal, 1);
crds.update_record_timestamp(&val.label().pubkey(), 1);
assert_eq!(crds.table[&val.label()].local_timestamp, 2);
assert_eq!(crds.table[&val.label()].ordinal, 1);
let mut ci = ContactInfo::default();
ci.wallclock += 1;
let val3 = CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(ci));
assert_eq!(crds.insert(val3, 3, GossipRoute::LocalMessage), Ok(()));
assert_eq!(*crds.purged.back().unwrap(), (value_hash, 3));
assert_eq!(crds.table[&val2.label()].local_timestamp, 3);
assert_eq!(crds.table[&val2.label()].ordinal, 2);
crds.update_record_timestamp(&val2.label().pubkey(), 1);
assert_eq!(crds.table[&val2.label()].local_timestamp, 2);
assert_eq!(crds.table[&val2.label()].ordinal, 1);
}
#[test]