MCPcopy Create free account
hub / github.com/apache/fory / test_circular_ref_schema_consistent

Function test_circular_ref_schema_consistent

rust/tests/tests/test_cross_language.rs:2231–2269  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2229#[test]
2230#[ignore]
2231fn test_circular_ref_schema_consistent() {
2232 let data_file_path = get_data_file();
2233 let bytes = fs::read(&data_file_path).unwrap();
2234
2235 let mut fory = Fory::builder()
2236 .compatible(false)
2237 .xlang(true)
2238 .track_ref(true)
2239 .build();
2240 fory.register::<CircularRefStruct>(601).unwrap();
2241
2242 // Deserialize as Rc<CircularRefStruct> since the whole struct needs ref tracking
2243 let obj: Rc<CircularRefStruct> = fory.deserialize(&bytes).unwrap();
2244
2245 // Verify the struct has the expected name
2246 assert_eq!(obj.name, "circular_test");
2247
2248 // Verify circular reference is preserved (self_ref points back to the same object)
2249 // RcWeak.upgrade() returns Option<Rc<T>> - should be Some if the strong ref exists
2250 let upgraded = obj.self_ref.upgrade();
2251 assert!(
2252 upgraded.is_some(),
2253 "self_ref.upgrade() should return Some (circular reference)"
2254 );
2255
2256 let self_ref = upgraded.unwrap();
2257 assert_eq!(self_ref.name, "circular_test");
2258
2259 // Verify it's actually pointing to the same object (circular)
2260 assert!(
2261 Rc::ptr_eq(&obj, &self_ref),
2262 "self_ref should point to the same object as obj (circular reference)"
2263 );
2264
2265 // Re-serialize and write back - serialize the Rc, not the dereferenced value
2266 // This ensures the Rc is registered before the RcWeak self-reference tries to reference it
2267 let new_bytes = fory.serialize(&obj).unwrap();
2268 fs::write(&data_file_path, new_bytes).unwrap();
2269}
2270
2271/// Test circular reference in COMPATIBLE mode (compatible=true).
2272/// Creates a struct where the 'self_ref' field points back to the same object.

Callers

nothing calls this directly

Calls 11

get_data_fileFunction · 0.70
deserializeMethod · 0.65
serializeMethod · 0.65
readFunction · 0.50
writeFunction · 0.50
unwrapMethod · 0.45
buildMethod · 0.45
track_refMethod · 0.45
xlangMethod · 0.45
compatibleMethod · 0.45
upgradeMethod · 0.45

Tested by

no test coverage detected