Skip to content

Commit 9df96f9

Browse files
authored
Fix the flakiness of new BinaryFormatter tests (#103476)
* 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
1 parent e976830 commit 9df96f9

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

src/libraries/System.Resources.Extensions/tests/BinaryFormatTests/Common/BasicObjectTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public abstract class BasicObjectTests<T> : SerializationTest<T> where T : ISeri
1616
[MemberData(nameof(SerializableObjects))]
1717
public void DeserializeStoredObjects(object value, TypeSerializableValue[] serializedData)
1818
{
19-
_ = value;
19+
// Following call may change the contents of the fields by invoking lazy-evaluated properties.
20+
EqualityExtensions.CheckEquals(value, value);
2021

2122
int platformIndex = serializedData.GetPlatformIndex();
2223
for (int i = 0; i < serializedData.Length; i++)
@@ -48,6 +49,9 @@ public void BasicObjectsRoundtrip(
4849
FormatterAssemblyStyle assemblyMatching,
4950
FormatterTypeStyle typeStyle)
5051
{
52+
// Following call may change the contents of the fields by invoking lazy-evaluated properties.
53+
EqualityExtensions.CheckEquals(value, value);
54+
5155
object deserialized = RoundTrip(value, typeStyle: typeStyle, assemblyMatching: assemblyMatching);
5256

5357
// string.Empty and DBNull are both singletons

0 commit comments

Comments
 (0)