Open
Description
As reported through another channel by an ion-schema-rust
user:
#[test]
fn test_non_determinism() {
use ion_rs::element::Element;
use ion_schema::{
system::SchemaSystem,
isl::{
IslSchema,
isl_constraint::v_1_0::fields,
isl_type::v_1_0::named_type,
isl_type_reference::v_1_0::{
variably_occurring_type_ref,
named_type_ref,
},
isl_range::Range
}
};
let element = Element::read_one("{str: 123, number: \"fox\"}").unwrap();
assert!((0..20).map(|_| {
let struct_type = named_type("my_type", vec![fields([
("str".into(), variably_occurring_type_ref(named_type_ref("string"), Range::required())),
("number".into(), variably_occurring_type_ref(named_type_ref("int"), Range::required())),
].into_iter())]);
let isl_schema = IslSchema::schema_v_1_0("my_schema", vec![], vec![struct_type], vec![], vec![]);
let mut schema_system = SchemaSystem::new(vec![]);
let schema = schema_system.load_schema_from_isl_schema_v1_0(isl_schema).unwrap();
let type_definition = schema.get_type("my_type").unwrap();
let violation = type_definition.validate(&element).unwrap_err();
violation
.flattened_violations()
.into_iter()
.cloned()
// Uncomment to make this test pass
// .sorted_by(|left, right| left.message().cmp(right.message()))
.collect::<Vec<_>>()
}).all_equal());
}
As far as I can tell this is because HashMap
is used to store field constraints and its hash function is randomly seeded.