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
39 changes: 11 additions & 28 deletions .github/workflows/Steeltoe.All.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ permissions:
pull-requests: write

env:
STEELTOE_MACOS_DIAGNOSE_HOSTNAME_LOOKUP: true
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: true
SOLUTION_FILE: 'src/Steeltoe.All.sln'
COMMON_TEST_ARGS: >-
--no-build --configuration Release --collect "XPlat Code Coverage" --logger trx --results-directory ${{ github.workspace }}/dumps
--settings coverlet.runsettings --blame-crash --blame-hang-timeout 3m
--no-build --configuration Release --collect "XPlat Code Coverage" --logger trx --results-directory ${{ github.workspace }}/TestOutput
--settings coverlet.runsettings --blame-crash --blame-hang-timeout 1m

jobs:
analyze:
Expand All @@ -36,9 +37,9 @@ jobs:
- os: ubuntu-latest
runDockerContainers: true
- os: windows-latest
skipFilter: Category!=Integration
skipIntegrationTests: true
- os: macos-latest
skipFilter: Category!=Integration
skipIntegrationTests: true
runs-on: ${{ matrix.os }}
continue-on-error: true

Expand Down Expand Up @@ -89,38 +90,20 @@ jobs:
- name: Build solution
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal

- name: Set skip filters for tests
shell: bash
run: |
echo SKIP_FILTER_NO_MEMORY_DUMPS="${{ matrix.skipFilter && format('{0}&Category!=MemoryDumps', matrix.skipFilter) || 'Category!=MemoryDumps' }}" >> $GITHUB_ENV
echo SKIP_FILTER_WITH_MEMORY_DUMPS="${{ matrix.skipFilter && format('{0}&Category=MemoryDumps', matrix.skipFilter) || 'Category=MemoryDumps' }}" >> $GITHUB_ENV

- name: Test (net10.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net10.0 --filter "${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net10.0) (memory dumps)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net10.0 --filter "${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net9.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net9.0 --filter "${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net9.0) (memory dumps)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net9.0 --filter "${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net8.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net8.0 --filter "${{ env.SKIP_FILTER_NO_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}
- name: Test
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "${{ matrix.skipIntegrationTests == true && 'Category!=MemoryDumps&Category!=Integration' || 'Category!=MemoryDumps' }}" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net8.0) (memory dumps)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net8.0 --filter "${{ env.SKIP_FILTER_WITH_MEMORY_DUMPS }}" ${{ env.COMMON_TEST_ARGS }}
- name: Test (memory dumps)
run: dotnet test src/Management/test/Endpoint.Test --filter "Category=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}

- name: Upload crash/hang dumps (on failure)
if: ${{ failure() }}
uses: actions/upload-artifact@v5
with:
name: FailedTestOutput-${{ matrix.os }}
path: |
${{ github.workspace }}/dumps/**/*.dmp
${{ github.workspace }}/dumps/**/Sequence_*.xml
${{ github.workspace }}/TestOutput/**/*.dmp
${{ github.workspace }}/TestOutput/**/Sequence_*.xml
if-no-files-found: ignore

- name: Report test results
Expand Down
31 changes: 9 additions & 22 deletions .github/workflows/component-shared-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ permissions:
pull-requests: write

env:
STEELTOE_MACOS_DIAGNOSE_HOSTNAME_LOOKUP: true
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: true
SOLUTION_FILE: 'src/Steeltoe.${{ inputs.component }}.slnf'
COMMON_TEST_ARGS: >-
--no-build --configuration Release --collect "XPlat Code Coverage" --logger trx --results-directory ${{ github.workspace }}/dumps
--settings coverlet.runsettings --blame-crash --blame-hang-timeout 3m
--no-build --configuration Release --collect "XPlat Code Coverage" --logger trx --results-directory ${{ github.workspace }}/TestOutput
--settings coverlet.runsettings --blame-crash --blame-hang-timeout 1m

jobs:
build:
Expand Down Expand Up @@ -79,35 +80,21 @@ jobs:
- name: Build solution
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal

- name: Test (net10.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net10.0 --filter "Category!=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}
- name: Test
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category!=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net10.0) (memory dumps)
- name: Test (memory dumps)
if: ${{ inputs.component == 'Management' }}
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net10.0 --filter "Category=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net9.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net9.0 --filter "Category!=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net9.0) (memory dumps)
if: ${{ inputs.component == 'Management' }}
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net9.0 --filter "Category=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net8.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net8.0 --filter "Category!=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}

- name: Test (net8.0) (memory dumps)
if: ${{ inputs.component == 'Management' }}
run: dotnet test ${{ env.SOLUTION_FILE }} --framework net8.0 --filter "Category=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}
run: dotnet test src/Management/test/Endpoint.Test --filter "Category=MemoryDumps" ${{ env.COMMON_TEST_ARGS }}

- name: Upload crash/hang dumps (on failure)
if: ${{ failure() }}
uses: actions/upload-artifact@v5
with:
name: FailedTestOutput-${{ inputs.OS }}-latest
path: |
${{ github.workspace }}/dumps/**/*.dmp
${{ github.workspace }}/dumps/**/Sequence_*.xml
${{ github.workspace }}/TestOutput/**/*.dmp
${{ github.workspace }}/TestOutput/**/Sequence_*.xml
if-no-files-found: ignore

- name: Report test results
Expand Down
23 changes: 6 additions & 17 deletions .github/workflows/sonarcube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ permissions:
pull-requests: write

env:
STEELTOE_MACOS_DIAGNOSE_HOSTNAME_LOOKUP: true
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: true
SOLUTION_FILE: 'src/Steeltoe.All.sln'
SONAR_TEST_ARGS: >-
--no-build --configuration Release --collect "XPlat Code Coverage" --logger trx --results-directory ${{ github.workspace }}
--no-build --configuration Release --collect "XPlat Code Coverage" --logger trx --results-directory ${{ github.workspace }}/TestOutput
--settings coverlet.runsettings -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.UseSourceLink=false

jobs:
Expand Down Expand Up @@ -79,23 +80,11 @@ jobs:
- name: Build solution
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal

- name: Test (net10.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category!=MemoryDumps" --framework net10.0 ${{ env.SONAR_TEST_ARGS }}
- name: Test
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category!=MemoryDumps" ${{ env.SONAR_TEST_ARGS }}

- name: Test (net10.0) (memory dumps)
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category=MemoryDumps" --framework net10.0 ${{ env.SONAR_TEST_ARGS }}

- name: Test (net9.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category!=MemoryDumps" --framework net9.0 ${{ env.SONAR_TEST_ARGS }}

- name: Test (net9.0) (memory dumps)
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category=MemoryDumps" --framework net9.0 ${{ env.SONAR_TEST_ARGS }}

- name: Test (net8.0)
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category!=MemoryDumps" --framework net8.0 ${{ env.SONAR_TEST_ARGS }}

- name: Test (net8.0) (memory dumps)
run: dotnet test ${{ env.SOLUTION_FILE }} --filter "Category=MemoryDumps" --framework net8.0 ${{ env.SONAR_TEST_ARGS }}
- name: Test (memory dumps)
run: dotnet test src/Management/test/Endpoint.Test --filter "Category=MemoryDumps" ${{ env.SONAR_TEST_ARGS }}

- name: End Sonar .NET scanner
if: ${{ !cancelled() && steps.sonar_begin.outcome == 'success' }}
Expand Down
12 changes: 9 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<Project>
<!-- Workaround for https://github.com/microsoft/testfx/issues/7045#issuecomment-3611560686 -->
<Target Name="WorkaroundMacOSDumpIssue" AfterTargets="Build"
Condition="$([MSBuild]::IsOSPlatform('OSX')) AND '$(UseAppHost)' != 'false' AND '$(OutputType)' == 'Exe' AND '$(TargetFramework)' != '' AND '$(RunCommand)' != '' AND '$(RunCommand)' != 'dotnet'">
<Exec Command="codesign --sign - --force --entitlements '$(MSBuildThisFileDirectory)macos-dump-entitlements.plist' '$(RunCommand)'" />
</Target>

<!--
Steeltoe: This file was copied from the .NET Aspire Configuration Schema generator
Steeltoe: The remainder of this file was copied from the .NET Aspire Configuration Schema generator
at https://github.com/dotnet/aspire/tree/cb7cc4d78f8dd2b4df1053a229493cdbf88f50df/src/Tools/ConfigurationSchemaGenerator.
-->

Expand Down Expand Up @@ -101,7 +107,7 @@
<Exec Command="$(GeneratorCommandLine)" />

<ItemGroup>
<FileWrites Include="$(GeneratedConfigurationSchemaOutputPath)" Condition="Exists('$(GeneratedConfigurationSchemaOutputPath)')"/>
<FileWrites Include="$(GeneratedConfigurationSchemaOutputPath)" Condition="Exists('$(GeneratedConfigurationSchemaOutputPath)')" />
</ItemGroup>
</Target>

Expand All @@ -123,7 +129,7 @@
</PropertyGroup>

<Warning Condition="'$(CurrentConfigurationSchemaFileContent)' != '$(GeneratedConfigurationSchemaFileContent)'"
Text="ConfigurationSchema.json is out of date for $(MSBuildProjectFile). Run 'dotnet build --no-incremental /p:UpdateConfigurationSchema=true' to update it." />
Text="ConfigurationSchema.json is out of date for $(MSBuildProjectFile). Run 'dotnet build --no-incremental /p:UpdateConfigurationSchema=true' to update it." />
</Target>

</Project>
16 changes: 16 additions & 0 deletions macos-dump-entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.debugger</key>
<true/>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>
7 changes: 1 addition & 6 deletions shared-test.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>
<NoWarn>$(NoWarn);S2094;S3717;SA1602;CA1062;CA1707;NU5104</NoWarn>
</PropertyGroup>

<PropertyGroup>
<!-- https://github.com/xunit/xunit/issues/3238#issuecomment-2770720936 -->
<TestTfmsInParallel>false</TestTfmsInParallel>
<DisableTestingPlatformServerCapability>true</DisableTestingPlatformServerCapability>
<NoWarn>$(NoWarn);S2094;S3717;SA1602;CA1062;CA1707;NU5104</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
38 changes: 36 additions & 2 deletions src/Common/src/Common/Net/DomainNameResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Steeltoe.Common.Net;

internal sealed class DomainNameResolver : IDomainNameResolver
{
private static readonly bool IsInDiagnosticsMode = Environment.GetEnvironmentVariable("STEELTOE_MACOS_DIAGNOSE_HOSTNAME_LOOKUP") == "true";
Comment thread
TimHess marked this conversation as resolved.

public static DomainNameResolver Instance { get; } = new();

private DomainNameResolver()
Expand Down Expand Up @@ -42,22 +44,44 @@ private DomainNameResolver()

public string? ResolveHostName(bool throwOnError = false)
{
// Gather diagnostic information to investigate intermittent failures on macOS.
string? resultFromGetHostName = null;
string? resultFromGetHostEntry = null;
bool? workaroundApplied = null;

try
{
string hostName = Dns.GetHostName();
resultFromGetHostName = hostName;

if (string.IsNullOrEmpty(hostName))
{
// Workaround for failure when running on macOS.
// See https://github.com/actions/runner-images/issues/1335 and https://github.com/dotnet/runtime/issues/36849.

hostName = "localhost";
workaroundApplied = true;
}

IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
return hostEntry.HostName;
resultFromGetHostEntry = hostEntry.HostName;

if (IsInDiagnosticsMode && string.IsNullOrEmpty(resultFromGetHostEntry))
{
throw new InvalidOperationException($"IPHostEntry.HostName returned {GetTextFor(resultFromGetHostEntry)}.");
}

return resultFromGetHostEntry;
}
catch (Exception)
catch (Exception exception)
{
if (IsInDiagnosticsMode)
{
throw new InvalidOperationException(
$"Failed to resolve hostname. GetHostName={GetTextFor(resultFromGetHostName)}, GetHostEntry={GetTextFor(resultFromGetHostEntry)}, WorkaroundApplied={workaroundApplied}",
exception);
}

if (throwOnError)
{
throw;
Expand All @@ -66,4 +90,14 @@ private DomainNameResolver()
return null;
}
}

private static string GetTextFor(string? value)
{
if (value == null)
{
return "(null)";
}

return value.Length == 0 ? "(empty)" : value;
}
}
44 changes: 44 additions & 0 deletions src/Common/test/TestResources/FluentAssertionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,48 @@ private static string ToJsonString(JsonDocument document)
writer.Flush();
return Encoding.UTF8.GetString(stream.ToArray());
}

/// <summary>
/// Same as the built-in Be() method, but allows specifying a custom comparer.
/// </summary>
/// <param name="source">
/// The source text to assert on.
/// </param>
/// <param name="expected">
/// The expected text.
/// </param>
/// <param name="comparer">
/// An equality comparer to compare values.
/// </param>
[CustomAssertion]
public static void Be(this StringAssertions source, string expected, IEqualityComparer<string> comparer)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(expected);
ArgumentNullException.ThrowIfNull(comparer);

object subject = source.Subject;
subject.Should().Be(expected, comparer);
}

/// <summary>
/// Same as the built-in Contain() method, but normalizes line endings upfront.
/// </summary>
/// <param name="source">
/// The source text to assert on.
/// </param>
/// <param name="expected">
/// The expected text.
/// </param>
[CustomAssertion]
public static void ContainLines(this StringAssertions source, string expected)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(expected);

string sourceText = source.Subject.ReplaceLineEndings();
string expectedText = expected.ReplaceLineEndings();

sourceText.Should().Contain(expectedText);
}
}
16 changes: 15 additions & 1 deletion src/Discovery/src/Consul/Registry/ConsulRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class ConsulRegistration : IServiceInstance
public bool IsSecure => _optionsMonitor.CurrentValue.EffectiveScheme == "https";

/// <inheritdoc />
public Uri Uri => new($"{_optionsMonitor.CurrentValue.EffectiveScheme}://{Host}:{Port}");
public Uri Uri => FormatUri();

/// <inheritdoc />
public Uri? NonSecureUri => IsSecure ? null : Uri;
Expand Down Expand Up @@ -73,6 +73,20 @@ internal ConsulRegistration(AgentServiceRegistration innerRegistration, IOptions
Metadata = innerRegistration.Meta.AsReadOnly();
}

private Uri FormatUri()
{
string scheme = _optionsMonitor.CurrentValue.EffectiveScheme;

try
{
return new Uri($"{scheme}://{Host}:{Port}");
}
catch (UriFormatException exception)
{
throw new UriFormatException($"Failed to build URI from components. Scheme={scheme}, Host={Host},Port={Port}.", exception);
}
}

/// <summary>
/// Creates a registration for the currently running app, to be submitted to the Consul server.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public async Task CanUseJsonFormatterWithScopes()
]
}

""");
""", IgnoreLineEndingsComparer.Instance);
}

[Fact]
Expand Down
Loading