1 // ----------------------------------------------------------------------------------------------
3 // / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4 // / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5 // / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6 // /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7 // ----------------------------------------------------------------------------------------------
9 // Copyright 2015-2025 Ćukasz "JustArchi" Domeradzki
10 // Contact: JustArchi@JustArchi.net
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
16 // http://www.apache.org/licenses/LICENSE-2.0
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
24 using System
.Collections
.Concurrent
;
25 using System
.Collections
.Generic
;
27 using ArchiSteamFarm
.Collections
;
28 using ArchiSteamFarm
.Core
;
29 using Microsoft
.VisualStudio
.TestTools
.UnitTesting
;
31 namespace ArchiSteamFarm
.Tests
;
33 #pragma warning disable CA1812 // False positive, the class is used during MSTest
35 internal sealed class ConcurrentTests
{
37 internal void ConcurrentDictionarySupportsWritingDuringLinq() {
38 ConcurrentDictionary
<ushort, bool> collection
= [];
40 for (byte i
= 0; i
< 10; i
++) {
41 collection
.TryAdd(i
, true);
44 Utilities
.InBackground(
46 for (ushort i
= 10; i
< ushort.MaxValue
; i
++) {
47 collection
.TryAdd(i
, true);
52 foreach (KeyValuePair
<ushort, bool> _
in collection
.AsLinqThreadSafeEnumerable().OrderBy(static entry
=> entry
.Key
)) { }
56 internal void ConcurrentHashSetSupportsWritingDuringLinq() {
57 ConcurrentHashSet
<ushort> collection
= [];
59 for (byte i
= 0; i
< 10; i
++) {
63 Utilities
.InBackground(
65 for (ushort i
= 10; i
< ushort.MaxValue
; i
++) {
71 foreach (ushort _
in collection
.AsLinqThreadSafeEnumerable().OrderBy(static entry
=> entry
)) { }
75 internal void ConcurrentListSupportsWritingDuringLinq() {
76 ConcurrentList
<ushort> collection
= [];
78 for (byte i
= 0; i
< 10; i
++) {
82 Utilities
.InBackground(
84 for (ushort i
= 10; i
< ushort.MaxValue
; i
++) {
90 foreach (ushort _
in collection
.AsLinqThreadSafeEnumerable().OrderBy(static entry
=> entry
)) { }
93 #pragma warning restore CA1812 // False positive, the class is used during MSTest