fix: race conditions (y-crdt/y-octo#51)

This commit is contained in:
DarkSky
2026-01-13 01:07:59 +08:00
committed by DarkSky
parent 0bd8160ed4
commit 89f0430242
2 changed files with 12 additions and 6 deletions
@@ -286,7 +286,16 @@ mod tests {
let mut reader = RawDecoder::new(&update);
let tag_type = reader.read_u8()?;
assert_eq!(Content::read(&mut reader, tag_type)?, *content);
let decoded = Content::read(&mut reader, tag_type)?;
match (&decoded, content) {
(Content::Type(decoded_ty), Content::Type(original_ty)) => {
let decoded_ty = decoded_ty.ty().expect("decoded ytype must exist");
let original_ty = original_ty.ty().expect("original ytype must exist");
assert_eq!(decoded_ty.kind(), original_ty.kind());
assert_eq!(decoded_ty.name.as_deref(), original_ty.name.as_deref());
}
_ => assert_eq!(decoded, *content),
}
Ok(())
}
@@ -55,12 +55,9 @@ impl PartialEq for YType {
impl PartialEq for YTypeRef {
fn eq(&self, other: &Self) -> bool {
// only check pointer equality
// currently no scenarios that involve cross document ytype comparisons
self.inner.ptr_eq(&other.inner)
|| match (self.ty(), other.ty()) {
(Some(l), Some(r)) => *l == *r,
(None, None) => true,
_ => false,
}
}
}