Skip to content

Commit

Permalink
Fix concurrency access causing flakyness in the test (#3867)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Jul 19, 2022
1 parent e85a600 commit 2ddf593
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
#if !NETSTANDARD1_0
using System.Collections.Concurrent;
#endif
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
Expand All @@ -20,7 +23,11 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel;
public class TestProperty : IEquatable<TestProperty>
{
private Type _valueType;
#if !NETSTANDARD1_0
private static readonly ConcurrentDictionary<string, Type> TypeCache = new();
#else
private static readonly Dictionary<string, Type> TypeCache = new();
#endif

#if NETSTANDARD1_0
private static bool DisableFastJson { get; set; } = true;
Expand Down Expand Up @@ -192,7 +199,11 @@ private Type GetType(string typeName)
{
if (type != null)
{
#if !NETSTANDARD1_0
TypeCache.TryAdd(typeName, type);
#else
TypeCache[typeName] = type;
#endif
return type;
}
}
Expand Down Expand Up @@ -260,7 +271,11 @@ private Type GetType(string typeName)

if (!DisableFastJson)
{
#if !NETSTANDARD1_0
TypeCache.TryAdd(typeName, type);
#else
TypeCache[typeName] = type;
#endif
}
return type;
}
Expand Down

0 comments on commit 2ddf593

Please sign in to comment.