diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index 129923b60942b..b3863a4965a10 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -750,7 +750,8 @@ public void NaNValuesComparedBitwise() var list2 = new RepeatedField { SampleNaNs.Regular, SampleNaNs.PayloadFlipped }; var list3 = new RepeatedField { SampleNaNs.Regular, SampleNaNs.SignallingFlipped }; - EqualityTester.AssertInequality(list1, list2); + // All SampleNaNs have the same hashcode under certain targets (e.g. netcoreapp2.1) + EqualityTester.AssertInequality(list1, list2, checkHashcode: false); EqualityTester.AssertEquality(list1, list3); Assert.True(list1.Contains(SampleNaNs.SignallingFlipped)); Assert.False(list2.Contains(SampleNaNs.SignallingFlipped)); diff --git a/csharp/src/Google.Protobuf.Test/EqualityTester.cs b/csharp/src/Google.Protobuf.Test/EqualityTester.cs index a669baba17bfd..d4b3c1341ac68 100644 --- a/csharp/src/Google.Protobuf.Test/EqualityTester.cs +++ b/csharp/src/Google.Protobuf.Test/EqualityTester.cs @@ -49,13 +49,14 @@ public static void AssertEquality(T first, T second) where T : IEquatable Assert.AreEqual(first.GetHashCode(), second.GetHashCode()); } - public static void AssertInequality(T first, T second) where T : IEquatable + public static void AssertInequality(T first, T second, bool checkHashcode = true) where T : IEquatable { Assert.IsFalse(first.Equals(second)); Assert.IsFalse(first.Equals((object) second)); // While this isn't a requirement, the chances of this test failing due to // coincidence rather than a bug are very small. - if (first != null && second != null) + // For such rare cases, an argument can be used to disable the check. + if (checkHashcode && first != null && second != null) { Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode()); }