Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
mvarendorff2 committed Nov 5, 2024
1 parent 34e6329 commit 294a417
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions src/Fluss.HotChocolate.IntegrationTest/HotChocolateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public async Task Setup()
Host.UseWebSockets();
Host.MapGraphQL();
Host.MapGraphQLWebSocket();

await Host.StartAsync();

var server = Host.Services.GetRequiredService<IServer>();
var addressFeature = server.Features.Get<IServerAddressesFeature>();
Address = addressFeature!.Addresses.First();
Expand All @@ -57,14 +57,14 @@ public async Task SubscriberReceivesLiveUpdates()
{
var tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(30000);

var channel = await SubscribeToTodos(default);

// Receive initial response
await channel.Reader.WaitToReadAsync(tokenSource.Token);
var ids = await channel.Reader.ReadAsync(tokenSource.Token);
Assert.That(ids, Is.Empty);

for (var i = 0; i < 10; i++)
{
var newId = await CreateTodo($"Todo {i}");
Expand All @@ -87,7 +87,7 @@ private async Task<Guid> CreateTodo(string todo)
query = "mutation CreateTodo($todo: String!) { createTodo(todo: $todo) { id } }",
variables = new { todo },
};

var response = await httpClient.PostAsJsonAsync("/graphql", body);
response.EnsureSuccessStatusCode();

Expand All @@ -113,7 +113,7 @@ private async Task<Channel<List<Guid>>> SubscribeToTodos(CancellationToken ct)
var message = Encoding.UTF8.GetString(buffer.AsSpan(0, result.Count));

if (message.Contains("connection_ack")) continue;

var document = JsonDocument.Parse(message);
var ids = document.RootElement.GetProperty("payload").GetProperty("data").GetProperty("todos").EnumerateArray()
.Select(t => t.GetProperty("id").GetGuid())
Expand All @@ -127,13 +127,13 @@ private async Task<Channel<List<Guid>>> SubscribeToTodos(CancellationToken ct)

const string init = """{"type":"connection_init"}""";
await socket.SendAsync(Encoding.UTF8.GetBytes(init).AsMemory(), WebSocketMessageType.Text, true, ct);

const string subscription = """{"id":"0","type":"subscribe","payload":{"query":"\n query Todos {\n todos { id } }\n","operationName":"Todos","variables":{}}}""";
await socket.SendAsync(Encoding.UTF8.GetBytes(subscription).AsMemory(), WebSocketMessageType.Text, true, ct);

return channel;
}

[TearDown]
public async Task TearDown()
{
Expand Down Expand Up @@ -265,7 +265,7 @@ public class TodoMutations
public async Task<TodoRead> CreateTodo([Service] IServiceProvider serviceProvider, string todo)
{
var unitOfWorkFactory = serviceProvider.GetSystemUserUnitOfWorkFactory();

return await unitOfWorkFactory.Commit(async unitOfWork =>
{
var created = await TodoWrite.Create(unitOfWork, todo);
Expand Down
6 changes: 3 additions & 3 deletions src/Fluss.HotChocolate/AddExtensionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private IReadOnlyCollection<EventListener> GetCurrentListeners(IReadOnlyDictiona
logger.LogWarning("Trying to add live results but {ContextData} is null!", nameof(contextData));
throw new InvalidOperationException("Cannot fetch ReadModels from null context.");

Check warning on line 62 in src/Fluss.HotChocolate/AddExtensionMiddleware.cs

View check run for this annotation

Codecov / codecov/patch

src/Fluss.HotChocolate/AddExtensionMiddleware.cs#L60-L62

Added lines #L60 - L62 were not covered by tests
}

if (!contextData.TryGetValue(nameof(IUnitOfWork), out var value) || value is not IUnitOfWork unitOfWork)
{
logger.LogWarning("Trying to add live results but {ContextData} does not contain UnitOfWork!", nameof(contextData));
Expand All @@ -70,15 +70,15 @@ private IReadOnlyCollection<EventListener> GetCurrentListeners(IReadOnlyDictiona

return unitOfWork.ReadModels.ToList().AsReadOnly();
}

private async IAsyncEnumerable<IQueryResult> LiveResults(IReadOnlyDictionary<string, object?>? contextData, QueryResult firstResult, IQueryRequest originalRequest)
{
if (contextData == null)
{
logger.LogWarning("Trying to add live results but {ContextData} is null!", nameof(contextData));
yield break;
}

var listeners = GetCurrentListeners(contextData);
yield return firstResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private static IUnitOfWork CreateIUnitOfWork(IResolverContext context)
.WithPrefilledVersion(
context.GetGlobalStateOrDefault<long?>(PrefillUnitOfWorkVersion)
);

// CleanAfter.Requests allows us to read the used ReadModels after the resolver and before returning
// the first result. The default CleanAfter.Resolver immediately returns the unitOfWork after the
// resolver, losing us valuable information.
Expand All @@ -28,7 +28,7 @@ private static IUnitOfWork CreateIUnitOfWork(IResolverContext context)

return unitOfWork;
}

public const string PrefillUnitOfWorkVersion = nameof(AddExtensionMiddleware) + ".prefillUnitOfWorkVersion";

public ArgumentKind Kind => ArgumentKind.Custom;
Expand Down
2 changes: 1 addition & 1 deletion src/Fluss/UnitOfWork/UnitOfWorkFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ await RetryPolicy
.ExecuteAsync(async () =>
{
var unitOfWork = serviceProvider.GetRequiredService<UnitOfWork>();

try
{
await action(unitOfWork);
Expand Down
2 changes: 1 addition & 1 deletion src/Fluss/UnitOfWork/UnitOfWorkRecordingProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ public async ValueTask<bool> IsStillUpToDate(IUnitOfWork unitOfWork, long? at =
return readModel.LastAcceptedEvent <= Version;
}
}

public ValueTask Return() => ValueTask.CompletedTask;

Check warning on line 98 in src/Fluss/UnitOfWork/UnitOfWorkRecordingProxy.cs

View check run for this annotation

Codecov / codecov/patch

src/Fluss/UnitOfWork/UnitOfWorkRecordingProxy.cs#L98

Added line #L98 was not covered by tests
}

0 comments on commit 294a417

Please sign in to comment.