Skip to content

Commit

Permalink
Fix the flakiness of new BinaryFormatter tests (#103476)
Browse files Browse the repository at this point in the history
* reproduce the problem by calling EqualityExtensions.CheckEquals up-front as it enumerates all properties and may change the contents of the fields

* do not cache the test input data, as some tests may by accident mutate it which may cause hard to repro failures based on the order of executed tests
  • Loading branch information
adamsitnik committed Jun 17, 2024
1 parent e976830 commit 9df96f9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public abstract class BasicObjectTests<T> : SerializationTest<T> where T : ISeri
[MemberData(nameof(SerializableObjects))]
public void DeserializeStoredObjects(object value, TypeSerializableValue[] serializedData)
{
_ = value;
// Following call may change the contents of the fields by invoking lazy-evaluated properties.
EqualityExtensions.CheckEquals(value, value);

int platformIndex = serializedData.GetPlatformIndex();
for (int i = 0; i < serializedData.Length; i++)
Expand Down Expand Up @@ -48,6 +49,9 @@ public void BasicObjectsRoundtrip(
FormatterAssemblyStyle assemblyMatching,
FormatterTypeStyle typeStyle)
{
// Following call may change the contents of the fields by invoking lazy-evaluated properties.
EqualityExtensions.CheckEquals(value, value);

object deserialized = RoundTrip(value, typeStyle: typeStyle, assemblyMatching: assemblyMatching);

// string.Empty and DBNull are both singletons
Expand Down
Loading

0 comments on commit 9df96f9

Please sign in to comment.