-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* still wip * maybe it works * redis support stuff * tests for redis 6 and 7 * guarantee one time disposal + ephemerals will try to dispose their underlying value + centralize TryDispose and TryDisposeAsync * rearrange FixedObjectPool stuff * reorganize some stuff * explicitly do not support CleanupAllAsync for redis * fix naming * ci changes * use ubuntu runner * run cosmos tests in a separate job * typo * try something else * use separate comments * change redis container wait strategy * combine results into one comment * multiline pwsh backticks + rename test result artifacts * download all artifacts
- Loading branch information
1 parent
14a5950
commit 700504d
Showing
34 changed files
with
2,324 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ on: | |
- '*' | ||
|
||
env: | ||
TIMEZONE: 'America/Chicago' | ||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | ||
DOTNET_NOLOGO: true | ||
ArtifactDirectory: ${{ github.workspace}}/artifacts | ||
|
@@ -22,9 +23,65 @@ defaults: | |
shell: pwsh | ||
|
||
jobs: | ||
build_and_test: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: write | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 8 | ||
dotnet-quality: ga | ||
|
||
- name: Restore dependencies | ||
run: dotnet restore | ||
|
||
- name: Build | ||
run: dotnet build --no-restore --configuration:Release | ||
|
||
- name: Test Core | ||
if: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} | ||
run: | | ||
dotnet test 'tests\Ephemerally.Tests\' ` | ||
--no-build ` | ||
--configuration:Release ` | ||
--logger:trx ` | ||
--results-directory ${{ env.ArtifactDirectory }} | ||
- name: Test Redis | ||
if: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} | ||
run: | | ||
dotnet test 'tests\Ephemerally.Redis.Tests\' ` | ||
--no-build ` | ||
--configuration:Release ` | ||
--logger:trx ` | ||
--results-directory ${{ env.ArtifactDirectory }} | ||
- name: Upload Test Results | ||
if: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: test-results | ||
path: ${{ env.ArtifactDirectory }}/**/*.trx | ||
|
||
# - name: Test Results Comment | ||
# if: always() | ||
# uses: im-open/[email protected] | ||
# with: | ||
# github-token: ${{ secrets.GITHUB_TOKEN }} | ||
# timezone: ${{ env.TIMEZONE }} | ||
# create-status-check: false | ||
# create-pr-comment: true | ||
# comment-identifier: 'TestResults' | ||
|
||
# Cosmos DB Emulator is broken on Ubuntu | ||
# https://github.com/Azure/azure-cosmos-db-emulator-docker/issues/56 | ||
build_and_test: | ||
|
||
build_and_test_cosmos: | ||
runs-on: windows-2022 | ||
permissions: | ||
checks: write | ||
|
@@ -50,14 +107,14 @@ jobs: | |
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 6 | ||
dotnet-version: 8 | ||
dotnet-quality: ga | ||
|
||
- name: Restore dependencies | ||
run: dotnet restore | ||
|
||
- name: Build | ||
run: dotnet build --no-restore | ||
run: dotnet build --no-restore --configuration:Release | ||
|
||
# Reenable when Ubuntu is fixed | ||
# - name: Wait for Cosmos Emulator | ||
|
@@ -68,16 +125,56 @@ jobs: | |
# timeout: 5000 | ||
# interval: 500 | ||
|
||
- name: Test | ||
- name: Test Cosmos | ||
if: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} | ||
run: dotnet test --no-build --verbosity normal --logger:trx --results-directory ${{ env.ArtifactDirectory }} | ||
run: | | ||
dotnet test 'tests\Ephemerally.Azure.Cosmos.Tests\' ` | ||
--no-build ` | ||
--configuration:Release ` | ||
--logger:trx ` | ||
--results-directory ${{ env.ArtifactDirectory }} | ||
- name: Upload Test Results | ||
if: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: cosmos-test-results | ||
path: ${{ env.ArtifactDirectory }}/**/*.trx | ||
|
||
# - name: Test Results Comment | ||
# if: always() | ||
# uses: im-open/[email protected] | ||
# with: | ||
# github-token: ${{ secrets.GITHUB_TOKEN }} | ||
# timezone: ${{ env.TIMEZONE }} | ||
# create-status-check: false | ||
# create-pr-comment: true | ||
# comment-identifier: 'CosmosTestResults' | ||
|
||
test_results_comment: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: write | ||
pull-requests: write | ||
needs: | ||
- build_and_test | ||
- build_and_test_cosmos | ||
|
||
steps: | ||
- name: Download Test Results | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: ${{ env.ArtifactDirectory }} | ||
|
||
- name: Publish Test Results | ||
uses: EnricoMi/publish-unit-test-result-action/composite@v2 | ||
- name: Test Results Comment | ||
if: always() | ||
uses: im-open/[email protected] | ||
with: | ||
files: | | ||
${{ env.ArtifactDirectory }}/**/*.trx | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
timezone: ${{ env.TIMEZONE }} | ||
create-status-check: false | ||
create-pr-comment: true | ||
comment-identifier: 'TestResults' | ||
|
||
tag: | ||
if: ${{ github.event_name != 'pull_request' }} | ||
|
@@ -87,6 +184,7 @@ jobs: | |
needs: | ||
- tag | ||
- build_and_test | ||
- build_and_test_cosmos | ||
if: ${{ github.event_name != 'pull_request' && needs.tag.outputs.prerelease-depth < 2 }} | ||
uses: ./.github/workflows/release.yml | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using StackExchange.Redis; | ||
|
||
namespace Ephemerally.Redis.Xunit; | ||
|
||
public class DefaultLocalRedisInstance | ||
{ | ||
public static ConnectionMultiplexer GetMultiplexer() => ConnectionMultiplexer.Connect(ConnectionString); | ||
|
||
|
||
public const string ConnectionString = "localhost:6379,allowAdmin=true"; | ||
|
||
public static ushort Port => 6379; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Ephemerally.Redis.Xunit/EphemeralRedisDatabaseFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Ephemerally.Redis.Xunit; | ||
|
||
internal class EphemeralRedisDatabaseFixture : EphemeralRedisDatabasePoolFixture | ||
{ | ||
private readonly Lazy<Task<IEphemeralRedisDatabase>> _database; | ||
|
||
public IEphemeralRedisDatabase Database => _database.Value.Result; | ||
|
||
public EphemeralRedisDatabaseFixture() | ||
{ | ||
_database = new(CreateDatabaseAsync); | ||
} | ||
|
||
protected virtual async Task<IEphemeralRedisDatabase> CreateDatabaseAsync() | ||
{ | ||
var multiplexer = await GetMultiplexer(); | ||
return multiplexer.GetDatabase() as IEphemeralRedisDatabase; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Ephemerally.Redis.Xunit/EphemeralRedisDatabasePoolFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using StackExchange.Redis; | ||
|
||
namespace Ephemerally.Redis.Xunit; | ||
|
||
public class EphemeralRedisDatabasePoolFixture : RedisMultiplexerFixture | ||
{ | ||
public EphemeralRedisDatabasePoolFixture() { } | ||
protected EphemeralRedisDatabasePoolFixture(IRedisTestContainerFixture containerFixture) | ||
: base(containerFixture) { } | ||
|
||
protected override async Task<IConnectionMultiplexer> CreateMultiplexerAsync() | ||
{ | ||
var implementation = await base.CreateMultiplexerAsync(); | ||
return new EphemeralConnectionMultiplexer(implementation); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Ephemerally.Redis.Xunit/Ephemerally.Redis.Xunit.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
<IsTestProject>false</IsTestProject> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<InternalsVisibleTo Include="Ephemerally.Redis.Tests" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Ephemerally.Redis\Ephemerally.Redis.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="IsExternalInit" Version="1.0.3"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="minver" Version="4.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="StackExchange.Redis" Version="2.7.20" /> | ||
<PackageReference Include="System.Linq.Async" Version="6.0.1" /> | ||
<PackageReference Include="Xunit" Version="2.4.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using StackExchange.Redis; | ||
using Xunit; | ||
|
||
namespace Ephemerally.Redis.Xunit; | ||
|
||
public class RedisMultiplexerFixture<TRedisTestContainerFixture>() | ||
: RedisMultiplexerFixture(new TRedisTestContainerFixture()) | ||
where TRedisTestContainerFixture : IRedisTestContainerFixture, new(); | ||
|
||
public class RedisMultiplexerFixture : IAsyncLifetime | ||
{ | ||
private readonly IRedisTestContainerFixture _containerFixture; | ||
private readonly Lazy<Task<IConnectionMultiplexer>> _multiplexer; | ||
|
||
public IConnectionMultiplexer Multiplexer => _multiplexer.Value.Result; | ||
|
||
protected Task<IConnectionMultiplexer> GetMultiplexer() => _multiplexer.Value; | ||
|
||
public RedisMultiplexerFixture() : this(UnmanagedTestContainerFixture.Instance) { } | ||
|
||
protected RedisMultiplexerFixture(IRedisTestContainerFixture containerFixture) | ||
{ | ||
_containerFixture = containerFixture; | ||
_multiplexer = new Lazy<Task<IConnectionMultiplexer>>(CreateMultiplexerAsync); | ||
} | ||
|
||
protected virtual async Task<IConnectionMultiplexer> CreateMultiplexerAsync() => | ||
await ConnectionMultiplexer.ConnectAsync(_containerFixture.ConnectionString); | ||
|
||
public virtual async Task InitializeAsync() | ||
{ | ||
await _containerFixture.InitializeAsync(); | ||
await _multiplexer.Value; | ||
} | ||
|
||
public virtual async Task DisposeAsync() | ||
{ | ||
if (!_multiplexer.IsValueCreated) return; | ||
|
||
var multiplexer = await GetMultiplexer(); | ||
await multiplexer.DisposeAsync(); | ||
await _containerFixture.DisposeAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Xunit; | ||
|
||
namespace Ephemerally.Redis.Xunit; | ||
|
||
public interface IRedisTestContainerFixture : IAsyncLifetime | ||
{ | ||
ushort PublicPort { get; } | ||
string ConnectionString { get; } | ||
} | ||
|
||
public sealed class UnmanagedTestContainerFixture : IRedisTestContainerFixture | ||
{ | ||
private static readonly Lazy<UnmanagedTestContainerFixture> _instance = new(() => new UnmanagedTestContainerFixture()); | ||
|
||
public static UnmanagedTestContainerFixture Instance => _instance.Value; | ||
|
||
private UnmanagedTestContainerFixture() { } | ||
|
||
public ushort PublicPort => DefaultLocalRedisInstance.Port; | ||
public string ConnectionString => DefaultLocalRedisInstance.ConnectionString; | ||
public Task InitializeAsync() => Task.CompletedTask; | ||
|
||
public Task DisposeAsync() => Task.CompletedTask; | ||
} |
Oops, something went wrong.