dotnet/runtime

Assert async-serialized content of dictionaries with ReferenceHandling.Preserve active

Open

#35,611 建立於 2020年4月29日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)C# (5,445 fork)batch import
area-System.Text.Jsonbacklog-cleanup-candidatehelp wantedno-recent-activitytest-enhancement

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

Following up on https://github.com/dotnet/runtime/pull/35046#discussion_r417063819:

In async tests for collections, we don't assert the result of serializing dictionaries with ReferenceHandling.Preserve active. This is because across multiple serialization operations, ref and id and metadata IDs may not be the same due to non-deterministic order of elements returned by GetEnumerator() for dictionaries. It is thus hard to compare the serialized results:

https://github.com/dotnet/runtime/blob/0fa0b905f65e57f5eb64dd556a07ead522930c8a/src/libraries/System.Text.Json/tests/Serialization/Stream.Collections.cs#L98-L102

We can include these types by overriding the GetEnumerator method for these collections to return a deterministic order, and/or using types with deterministic order e.g. OrderedDictionary, SortedDictionary.

貢獻者指南