Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrency access causing flakyness in the test #3867

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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