Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion test/IntegrationTests/Helpers/CollectorRequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static async Task<MemoryStream> ReadBodyToMemoryAsync(this HttpContext ct
ctx.Request.Body.Position = 0;

var inMemory = new MemoryStream();
await ctx.Request.Body.CopyToAsync(inMemory);
await ctx.Request.Body.CopyToAsync(inMemory).ConfigureAwait(false);

inMemory.Position = 0;

Expand Down
6 changes: 3 additions & 3 deletions test/IntegrationTests/Helpers/CollectorResponseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public static async Task GenerateEmptyProtobufResponseAsync<T>(this HttpContext
using var outMemory = new MemoryStream();
responseMessage.WriteTo(outMemory);

await ctx.Response.Body.WriteAsync(outMemory.GetBuffer(), 0, (int)outMemory.Length);
await ctx.Response.CompleteAsync();
await ctx.Response.Body.WriteAsync(outMemory.GetBuffer().AsMemory(0, (int)outMemory.Length)).ConfigureAwait(false);
await ctx.Response.CompleteAsync().ConfigureAwait(false);
}

public static async Task GenerateEmptyJsonResponseAsync(this HttpContext ctx)
{
ctx.Response.ContentType = "application/json";
await ctx.Response.WriteAsync("{}");
await ctx.Response.WriteAsync("{}").ConfigureAwait(false);
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace IntegrationTests.Helpers.Compatibility;

public static class DictionaryExtensions
internal static class DictionaryExtensions
{
public static TValue? GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
{
Expand Down Expand Up @@ -48,7 +48,9 @@ public static bool TryGetValue<TValue>(this IDictionary dictionary, object key,
// if a key is not found, but let's use try/catch to be defensive against misbehaving implementations
valueObj = dictionary[key];
}
catch
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception)
#pragma warning restore CA1031 // Do not catch general exception types
{
valueObj = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if NETFRAMEWORK
using System.Globalization;

namespace System.Text;

internal static class StringBuilderExtensions
{
public static StringBuilder AppendLine(this StringBuilder stringBuilder, CultureInfo cultureInfo, string value)
{
return stringBuilder.AppendLine(value);
}

public static StringBuilder Append(this StringBuilder stringBuilder, CultureInfo cultureInfo, string value)
{
return stringBuilder.AppendLine(value);
}
}
#endif
11 changes: 6 additions & 5 deletions test/IntegrationTests/Helpers/DockerNetworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ internal static class DockerNetworkHelper
/// <returns>Docker network name</returns>
internal static async Task<string> SetupIntegrationTestsNetworkAsync()
{
var client = new DockerClientConfiguration().CreateClient();
var networks = await client.Networks.ListNetworksAsync();
using var clientConfiguration = new DockerClientConfiguration();
var client = clientConfiguration.CreateClient();
var networks = await client.Networks.ListNetworksAsync().ConfigureAwait(false);
var network = networks.FirstOrDefault(x => x.Name == IntegrationTestsNetworkName);

if (network != null)
Expand All @@ -33,7 +34,7 @@ internal static async Task<string> SetupIntegrationTestsNetworkAsync()
}
else
{
await client.Networks.DeleteNetworkAsync(network.ID);
await client.Networks.DeleteNetworkAsync(network.ID).ConfigureAwait(false);
}
}

Expand All @@ -53,10 +54,10 @@ internal static async Task<string> SetupIntegrationTestsNetworkAsync()
Subnet = "10.1.1.0/24"
});

var result = await client.Networks.CreateNetworkAsync(networkParams);
var result = await client.Networks.CreateNetworkAsync(networkParams).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(result.ID))
{
throw new Exception("Could not create docker network");
throw new InvalidOperationException("Could not create docker network");
}

return IntegrationTestsNetworkName;
Expand Down
4 changes: 2 additions & 2 deletions test/IntegrationTests/Helpers/DockerSystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace IntegrationTests.Helpers;

internal class DockerSystemHelper
internal sealed class DockerSystemHelper
{
public static async Task<bool> GetIsWindowsEngineEnabled()
{
using var client = GetDockerClient();

var version = await client.System.GetVersionAsync();
var version = await client.System.GetVersionAsync().ConfigureAwait(false);
return version.Os.IndexOf("Windows", StringComparison.OrdinalIgnoreCase) > -1;
}

Expand Down
47 changes: 37 additions & 10 deletions test/IntegrationTests/Helpers/EnvironmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Specialized;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Xunit.Abstractions;

namespace IntegrationTests.Helpers;

public class EnvironmentHelper
internal sealed class EnvironmentHelper
{
private static readonly string RuntimeFrameworkDescription = RuntimeInformation.FrameworkDescription.ToLower();
#pragma warning disable CA1308 // Normalize strings to uppercase
private static readonly string RuntimeFrameworkDescription = RuntimeInformation.FrameworkDescription.ToLowerInvariant();
#pragma warning restore CA1308 // Normalize strings to uppercase

private readonly ITestOutputHelper _output;
private readonly int _major;
Expand Down Expand Up @@ -41,11 +44,15 @@ public EnvironmentHelper(

var parts = _targetFramework.FrameworkName.Split(',');
_runtime = parts[0];
_isCoreClr = _runtime.Equals(EnvironmentTools.CoreFramework);
_isCoreClr = _runtime.Equals(EnvironmentTools.CoreFramework, StringComparison.Ordinal);

#if NET
var versionParts = parts[1].Replace("Version=v", string.Empty, StringComparison.Ordinal).Split('.');
#else
var versionParts = parts[1].Replace("Version=v", string.Empty).Split('.');
_major = int.Parse(versionParts[0]);
_minor = int.Parse(versionParts[1]);
#endif
_major = int.Parse(versionParts[0], CultureInfo.InvariantCulture);
_minor = int.Parse(versionParts[1], CultureInfo.InvariantCulture);

if (versionParts.Length == 3)
{
Expand Down Expand Up @@ -77,7 +84,13 @@ public EnvironmentHelper(

public static bool IsCoreClr()
{
return RuntimeFrameworkDescription.Contains("core") || Environment.Version.Major >= 5;
return
#if NET
RuntimeFrameworkDescription.Contains("core", StringComparison.Ordinal)
#else
RuntimeFrameworkDescription.Contains("core")
#endif
|| Environment.Version.Major >= 5;
}

public static string GetNukeBuildOutput()
Expand All @@ -92,7 +105,7 @@ public static string GetNukeBuildOutput()
return nukeOutputPath;
}

throw new Exception($"Unable to find Nuke output at: {nukeOutputPath}. Ensure Nuke has run first.");
throw new InvalidOperationException($"Unable to find Nuke output at: {nukeOutputPath}. Ensure Nuke has run first.");
}

public static bool IsRunningOnCI()
Expand Down Expand Up @@ -138,14 +151,20 @@ public string GetProfilerPath()
return _profilerFileLocation;
}

throw new Exception($"Unable to find profiler at: {profilerPath}");
throw new InvalidOperationException($"Unable to find profiler at: {profilerPath}");
}

public string GetTestApplicationPath(string packageVersion = "", string framework = "", TestAppStartupMode startupMode = TestAppStartupMode.Auto)
{
var extension = startupMode switch
{
TestAppStartupMode.Auto => IsCoreClr() || _testApplicationDirectory.Contains("aspnet") ? ".dll" : GetExecutableExtension(),
TestAppStartupMode.Auto => IsCoreClr() ||
#if NET
_testApplicationDirectory.Contains("aspnet", StringComparison.Ordinal)
#else
_testApplicationDirectory.Contains("aspnet")
#endif
? ".dll" : GetExecutableExtension(),
TestAppStartupMode.DotnetCLI => ".dll",
TestAppStartupMode.Exe => GetExecutableExtension(),
_ => throw new InvalidOperationException($"Unknown startup mode '{startupMode}'")
Expand All @@ -165,7 +184,11 @@ public string GetTestApplicationExecutionSource()
{
string executor;

#if NET
if (_testApplicationDirectory.Contains("aspnet", StringComparison.Ordinal))
#else
if (_testApplicationDirectory.Contains("aspnet"))
#endif
{
executor = $"C:\\Program Files{(Environment.Is64BitProcess ? string.Empty : " (x86)")}\\IIS Express\\iisexpress.exe";
}
Expand All @@ -180,7 +203,7 @@ public string GetTestApplicationExecutionSource()

if (!File.Exists(executor))
{
throw new Exception($"Unable to find executing assembly at {executor}");
throw new InvalidOperationException($"Unable to find executing assembly at {executor}");
}
}

Expand All @@ -203,7 +226,11 @@ public string GetTestApplicationApplicationOutputDirectory(string packageVersion
var targetFramework = string.IsNullOrEmpty(framework) ? GetTargetFramework() : framework;
var baseBinDirectory = GetTestApplicationBaseBinDirectory();

#if NET
if (_testApplicationDirectory.Contains("aspnet", StringComparison.Ordinal))
#else
if (_testApplicationDirectory.Contains("aspnet"))
#endif
{
return Path.Combine(
baseBinDirectory,
Expand Down
8 changes: 6 additions & 2 deletions test/IntegrationTests/Helpers/EnvironmentTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace IntegrationTests.Helpers;
/// <summary>
/// General use utility methods for all tests and tools.
/// </summary>
public static class EnvironmentTools
internal static class EnvironmentTools
{
public const string ProfilerClsId = "{918728DD-259F-4A6A-AC2B-B85E1B658318}";
public const string DotNetFramework = ".NETFramework";
Expand All @@ -34,7 +34,7 @@ public static class EnvironmentTools

if (currentDirectory == null || !currentDirectory.Exists)
{
throw new Exception($"Unable to find solution directory from: {startDirectory}");
throw new InvalidOperationException($"Unable to find solution directory from: {startDirectory}");
}
}

Expand Down Expand Up @@ -90,7 +90,9 @@ public static bool IsMacOS()

public static string GetPlatform()
{
#pragma warning disable CA1308 // Normalize strings to uppercase
return RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
#pragma warning restore CA1308 // Normalize strings to uppercase
}

public static bool IsX64()
Expand Down Expand Up @@ -125,7 +127,9 @@ public static string GetBuildConfiguration()

public static string GetClrProfilerDirectoryName()
{
#pragma warning disable CA1308 // Normalize strings to uppercase
return $"{GetClrProfilerOSDirectoryName()}-{GetPlatformDir().ToLowerInvariant()}";
#pragma warning restore CA1308 // Normalize strings to uppercase
}

private static string? GetClrProfilerOSDirectoryName()
Expand Down
8 changes: 4 additions & 4 deletions test/IntegrationTests/Helpers/FirewallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

namespace IntegrationTests.Helpers;

public static class FirewallHelper
internal static class FirewallHelper
{
public static FirewallPort OpenWinPort(int port, ITestOutputHelper output)
{
string ruleName = $"TraceAgent-{port}";
string psCommand = $"New-NetFirewallRule -DisplayName '{ruleName}' -Direction Inbound -LocalPort {port} -Protocol TCP -Action Allow -Profile Any";
var ruleName = $"TraceAgent-{port}";
var psCommand = $"New-NetFirewallRule -DisplayName '{ruleName}' -Direction Inbound -LocalPort {port} -Protocol TCP -Action Allow -Profile Any";

PowershellHelper.RunCommand(psCommand, output);

Expand All @@ -19,7 +19,7 @@ public static FirewallPort OpenWinPort(int port, ITestOutputHelper output)

public static void CloseWinPort(string ruleName, ITestOutputHelper output)
{
string psCommand = $"Remove-NetFirewallRule -DisplayName {ruleName}";
var psCommand = $"Remove-NetFirewallRule -DisplayName {ruleName}";

PowershellHelper.RunCommand(psCommand, output);
}
Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/Helpers/FirewallPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace IntegrationTests.Helpers;

public class FirewallPort : IDisposable
internal sealed class FirewallPort : IDisposable
{
private readonly ITestOutputHelper _output;

Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/Helpers/GacEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace IntegrationTests.Helpers;

public class GacEntry : IDisposable
internal sealed class GacEntry : IDisposable
{
private readonly string _assemblyPath;
private readonly Publish _publish = new Publish();
Expand Down
17 changes: 10 additions & 7 deletions test/IntegrationTests/Helpers/HealthzHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,35 @@ namespace IntegrationTests.Helpers;

internal static class HealthzHelper
{
private static readonly HttpClient HttpClient = new();

public static async Task TestAsync(string healthzUrl, ITestOutputHelper output)
{
output.WriteLine($"Testing healthz endpoint: {healthzUrl}");
HttpClient client = new();

var intervalMilliseconds = 500;
var maxMillisecondsToWait = 15_000;
var maxRetries = maxMillisecondsToWait / intervalMilliseconds;
for (int retry = 0; retry < maxRetries; retry++)
const int intervalMilliseconds = 500;
const int maxMillisecondsToWait = 15_000;
const int maxRetries = maxMillisecondsToWait / intervalMilliseconds;
for (var retry = 0; retry < maxRetries; retry++)
{
try
{
var response = await client.GetAsync(healthzUrl);
var response = await HttpClient.GetAsync(new Uri(healthzUrl)).ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK)
{
return;
}

output.WriteLine($"Healthz endpoint returned HTTP status code: {response.StatusCode}");
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
{
output.WriteLine($"Healthz endpoint call failed: {ex.Message}");
}

await Task.Delay(intervalMilliseconds);
await Task.Delay(intervalMilliseconds).ConfigureAwait(false);
}

throw new InvalidOperationException($"Healthz endpoint never returned OK: {healthzUrl}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

namespace IntegrationTests.Helpers;

public class InstrumentedProcessHelper
internal static class InstrumentedProcessHelper
{
public static Process? Start(string executable, string? arguments, EnvironmentHelper environmentHelper)
{
#if NET
ArgumentNullException.ThrowIfNull(environmentHelper);
#else
if (environmentHelper == null)
{
throw new ArgumentNullException(nameof(environmentHelper));
}
#endif

var startInfo = new ProcessStartInfo(executable, arguments ?? string.Empty);

Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/Helpers/ListHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static ICollection<KeyValuePair<string, string>> ToEnvironmentVariablesLi
{
return list.Select(x =>
{
var keyValuePair = x.Split(new[] { '=' }, 2);
var keyValuePair = x.Split(['='], 2);

return new KeyValuePair<string, string>(keyValuePair[0], keyValuePair[1]);
})
Expand Down
Loading
Loading