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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public sealed class RedisEventStreamBrokerTests(RedisFixture fixture)
public async Task Subscribe_Should_DeliverPublishedEvent_When_RedisBrokerPublishes()
{
// arrange
fixture.SkipWhenUnavailable();
var channel = fixture.NextChannel();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var ready = Channel.CreateUnbounded<bool>();
Expand Down Expand Up @@ -44,6 +45,7 @@ public async Task Subscribe_Should_DeliverPublishedEvent_When_RedisBrokerPublish
public async Task Subscribe_Should_MergeAllChannelsIntoOneStream_When_MultipleTopicsSubscribed()
{
// arrange
fixture.SkipWhenUnavailable();
var channelA = fixture.NextChannel();
var channelB = fixture.NextChannel();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
Expand Down Expand Up @@ -75,6 +77,7 @@ public async Task Subscribe_Should_MergeAllChannelsIntoOneStream_When_MultipleTo
public async Task Subscribe_Should_DeliverEveryEventToEachSubscriber_When_TwoConcurrentSubscribers()
{
// arrange
fixture.SkipWhenUnavailable();
var channel = fixture.NextChannel();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var ready = Channel.CreateUnbounded<bool>();
Expand Down Expand Up @@ -118,6 +121,7 @@ public async Task Subscribe_Should_DeliverEveryEventToEachSubscriber_When_TwoCon
public async Task Subscribe_Should_ThrowInvalidCursor_When_CursorSupplied()
{
// arrange
fixture.SkipWhenUnavailable();
var channel = fixture.NextChannel();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var services = CreateServices();
Expand All @@ -141,6 +145,7 @@ public async Task Subscribe_Should_ThrowInvalidCursor_When_CursorSupplied()
public async Task Subscribe_Should_CloseConsumerCleanly_When_CancellationRequested()
{
// arrange
fixture.SkipWhenUnavailable();
var channel = fixture.NextChannel();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var ready = Channel.CreateUnbounded<bool>();
Expand Down Expand Up @@ -177,6 +182,7 @@ public async Task Subscribe_Should_CloseConsumerCleanly_When_CancellationRequest
public async Task DisposeAsync_Should_NotDisposeConnectionMultiplexer_When_CallerSupplied()
{
// arrange
fixture.SkipWhenUnavailable();
await using var multiplexer = await ConnectionMultiplexer.ConnectAsync(fixture.ConnectionString);
var services = new ServiceCollection();
services.AddRedisEventStreamBroker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace HotChocolate.Fusion.Subscriptions.Redis;
/// </summary>
/// <remarks>
/// The default path starts Redis through Testcontainers. Set REDIS_CONNECTION_STRING to use an
/// existing Redis instance instead.
/// existing Redis instance instead; tests skip when that instance cannot be reached.
/// </remarks>
public sealed class RedisFixture : IAsyncLifetime
{
Expand All @@ -32,6 +32,8 @@ public RedisFixture()

public string ConnectionString { get; private set; } = null!;

public string? SkipReason { get; private set; }

public string NextChannel()
=> "events-" + Guid.NewGuid().ToString("N");

Expand All @@ -45,9 +47,9 @@ public async ValueTask InitializeAsync()
}
catch (Exception ex)
{
Assert.Skip(
SkipReason =
"REDIS_CONNECTION_STRING did not point to a usable Redis instance: "
+ ex.Message);
+ ex.Message;
}

return;
Expand Down Expand Up @@ -85,6 +87,18 @@ await subscriber
.ConfigureAwait(false);
}

/// <summary>
/// Skips the calling test when REDIS_CONNECTION_STRING points at an instance that could not
/// be reached.
/// </summary>
public void SkipWhenUnavailable()
{
if (SkipReason is not null)
{
Assert.Skip(SkipReason);
}
}

private async Task<ConnectionMultiplexer> GetPublisherAsync()
{
if (_publisher is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public RedisSubscriptionTests(RedisFixture fixture)
public async Task Subscribe_Should_DeliverEventWithCrossSchemaData_When_RedisBrokerPublishes()
{
// arrange
_fixture.SkipWhenUnavailable();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var channel = _fixture.NextChannel();
var ready = CreateReadyChannel();
Expand Down
Loading