chore(deps): update docker/build-push-action action to v6.11.0
[ArchiSteamFarm.git] / ArchiSteamFarm.Tests / ConcurrentTests.cs
blob7fd1144c9e96483d50212202ae85df0e223eddfb
1 // ----------------------------------------------------------------------------------------------
2 // _ _ _ ____ _ _____
3 // / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4 // / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5 // / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6 // /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7 // ----------------------------------------------------------------------------------------------
8 // |
9 // Copyright 2015-2025 Ɓukasz "JustArchi" Domeradzki
10 // Contact: JustArchi@JustArchi.net
11 // |
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
15 // |
16 // http://www.apache.org/licenses/LICENSE-2.0
17 // |
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;
26 using System.Linq;
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
34 [TestClass]
35 internal sealed class ConcurrentTests {
36 [TestMethod]
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(
45 () => {
46 for (ushort i = 10; i < ushort.MaxValue; i++) {
47 collection.TryAdd(i, true);
49 }, true
52 foreach (KeyValuePair<ushort, bool> _ in collection.AsLinqThreadSafeEnumerable().OrderBy(static entry => entry.Key)) { }
55 [TestMethod]
56 internal void ConcurrentHashSetSupportsWritingDuringLinq() {
57 ConcurrentHashSet<ushort> collection = [];
59 for (byte i = 0; i < 10; i++) {
60 collection.Add(i);
63 Utilities.InBackground(
64 () => {
65 for (ushort i = 10; i < ushort.MaxValue; i++) {
66 collection.Add(i);
68 }, true
71 foreach (ushort _ in collection.AsLinqThreadSafeEnumerable().OrderBy(static entry => entry)) { }
74 [TestMethod]
75 internal void ConcurrentListSupportsWritingDuringLinq() {
76 ConcurrentList<ushort> collection = [];
78 for (byte i = 0; i < 10; i++) {
79 collection.Add(i);
82 Utilities.InBackground(
83 () => {
84 for (ushort i = 10; i < ushort.MaxValue; i++) {
85 collection.Add(i);
87 }, true
90 foreach (ushort _ in collection.AsLinqThreadSafeEnumerable().OrderBy(static entry => entry)) { }
93 #pragma warning restore CA1812 // False positive, the class is used during MSTest