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 caching of Lazy<T> in tests #68473

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -84,11 +84,12 @@ protected virtual void Dispose(bool disposing)
protected string GetRandomLinkName() => GetTestFileName() + ".link";
protected string GetRandomDirName() => GetTestFileName() + "_dir";

protected string GetRandomFilePath() => Path.Combine(ActualTestDirectory.Value, GetRandomFileName());
protected string GetRandomLinkPath() => Path.Combine(ActualTestDirectory.Value, GetRandomLinkName());
protected string GetRandomDirPath() => Path.Combine(ActualTestDirectory.Value, GetRandomDirName());
protected string GetRandomFilePath() => Path.Combine(TestDirectoryActualCasing, GetRandomFileName());
protected string GetRandomLinkPath() => Path.Combine(TestDirectoryActualCasing, GetRandomLinkName());
protected string GetRandomDirPath() => Path.Combine(TestDirectoryActualCasing, GetRandomDirName());

private Lazy<string> ActualTestDirectory => new Lazy<string>(() => GetTestDirectoryActualCasing());
private string _testDirectoryActualCasing;
private string TestDirectoryActualCasing => _testDirectoryActualCasing ?? (_testDirectoryActualCasing = GetTestDirectoryActualCasing());
jkotas marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>Gets a test file full path that is associated with the call site.</summary>
/// <param name="index">An optional index value to use as a suffix on the file name. Typically a loop index.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static partial class PlatformDetection
// do it in a way that failures don't cascade.
//

private static Lazy<bool> s_IsInHelix => new Lazy<bool>(() => Environment.GetEnvironmentVariables().Keys.Cast<string>().Any(key => key.StartsWith("HELIX")));
private static readonly Lazy<bool> s_IsInHelix = new Lazy<bool>(() => Environment.GetEnvironmentVariables().Keys.Cast<string>().Any(key => key.StartsWith("HELIX")));
public static bool IsInHelix => s_IsInHelix.Value;

public static bool IsNetCore => Environment.Version.Major >= 5 || RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase);
Expand Down Expand Up @@ -66,9 +66,9 @@ public static partial class PlatformDetection
public static bool Is64BitProcess => IntPtr.Size == 8;
public static bool IsNotWindows => !IsWindows;

private static Lazy<bool> s_isCheckedRuntime => new Lazy<bool>(() => AssemblyConfigurationEquals("Checked"));
private static Lazy<bool> s_isReleaseRuntime => new Lazy<bool>(() => AssemblyConfigurationEquals("Release"));
private static Lazy<bool> s_isDebugRuntime => new Lazy<bool>(() => AssemblyConfigurationEquals("Debug"));
private static readonly Lazy<bool> s_isCheckedRuntime = new Lazy<bool>(() => AssemblyConfigurationEquals("Checked"));
private static readonly Lazy<bool> s_isReleaseRuntime = new Lazy<bool>(() => AssemblyConfigurationEquals("Release"));
private static readonly Lazy<bool> s_isDebugRuntime = new Lazy<bool>(() => AssemblyConfigurationEquals("Debug"));

public static bool IsCheckedRuntime => s_isCheckedRuntime.Value;
public static bool IsReleaseRuntime => s_isReleaseRuntime.Value;
Expand Down Expand Up @@ -209,7 +209,7 @@ public static bool IsMetadataTokenSupported
// Linux - OpenSsl supports alpn from openssl 1.0.2 and higher.
// OSX - SecureTransport doesn't expose alpn APIs. TODO https://github.com/dotnet/runtime/issues/27727
// Android - Platform supports alpn from API level 29 and higher
private static Lazy<bool> s_supportsAlpn = new Lazy<bool>(GetAlpnSupport);
private static readonly Lazy<bool> s_supportsAlpn = new Lazy<bool>(GetAlpnSupport);
private static bool GetAlpnSupport()
{
if (IsWindows && !IsWindows7 && !IsNetFramework)
Expand Down Expand Up @@ -238,11 +238,11 @@ private static bool GetAlpnSupport()
public static bool SupportsAlpn => s_supportsAlpn.Value;
public static bool SupportsClientAlpn => SupportsAlpn || IsOSX || IsMacCatalyst || IsiOS || IstvOS;

private static Lazy<bool> s_supportsTls10 = new Lazy<bool>(GetTls10Support);
private static Lazy<bool> s_supportsTls11 = new Lazy<bool>(GetTls11Support);
private static Lazy<bool> s_supportsTls12 = new Lazy<bool>(GetTls12Support);
private static Lazy<bool> s_supportsTls13 = new Lazy<bool>(GetTls13Support);
private static Lazy<bool> s_sendsCAListByDefault = new Lazy<bool>(GetSendsCAListByDefault);
private static readonly Lazy<bool> s_supportsTls10 = new Lazy<bool>(GetTls10Support);
private static readonly Lazy<bool> s_supportsTls11 = new Lazy<bool>(GetTls11Support);
private static readonly Lazy<bool> s_supportsTls12 = new Lazy<bool>(GetTls12Support);
private static readonly Lazy<bool> s_supportsTls13 = new Lazy<bool>(GetTls13Support);
private static readonly Lazy<bool> s_sendsCAListByDefault = new Lazy<bool>(GetSendsCAListByDefault);

public static bool SupportsTls10 => s_supportsTls10.Value;
public static bool SupportsTls11 => s_supportsTls11.Value;
Expand All @@ -251,7 +251,7 @@ private static bool GetAlpnSupport()
public static bool SendsCAListByDefault => s_sendsCAListByDefault.Value;
public static bool SupportsSendingCustomCANamesInTls => UsesAppleCrypto || IsOpenSslSupported || (PlatformDetection.IsWindows8xOrLater && SendsCAListByDefault);

private static Lazy<bool> s_largeArrayIsNotSupported = new Lazy<bool>(IsLargeArrayNotSupported);
private static readonly Lazy<bool> s_largeArrayIsNotSupported = new Lazy<bool>(IsLargeArrayNotSupported);

[MethodImpl(MethodImplOptions.NoOptimization)]
private static bool IsLargeArrayNotSupported()
Expand Down