Skip to content
Closed
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
6 changes: 6 additions & 0 deletions logs/log1755872208.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Log 1755872208

## tests/Proto.Actor.Tests/Headers/MessageHeaderTests.cs
- Replaced `TaskCompletionSource` usage with a `TestProbe` to observe headers, following testing guidelines.
- Forwarded observed headers to the probe and asserted with `ExpectNextUserMessageAsync<MessageHeader>` and `ExpectEmptyMailboxAsync`.
- Added `Proto.TestKit` import and disposed the `ActorSystem` asynchronously.
24 changes: 12 additions & 12 deletions tests/Proto.Actor.Tests/Headers/MessageHeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Threading.Tasks;
using FluentAssertions;
using Proto.TestKit;
using Proto.Utils;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -31,11 +32,13 @@ Sender PropagateHeaders(Sender next) =>

var headers = MessageHeader.Empty.With("foo", "bar");

var system = new ActorSystem(ActorSystemConfig.Setup() with
await using var system = new ActorSystem(ActorSystemConfig.Setup() with
{
ConfigureRootContext = context => context.WithHeaders(headers)
});

var (probe, probePid) = system.CreateTestProbe();

var props1 = Props.FromFunc(ctx =>
{
switch (ctx.Message)
Expand All @@ -53,20 +56,17 @@ Sender PropagateHeaders(Sender next) =>

var pid1 = system.Root.Spawn(props1);

var tcs1 = new TaskCompletionSource<MessageHeader>();
var tcs2 = new TaskCompletionSource<MessageHeader>();

var props2 = Props.FromFunc(ctx =>
{
switch (ctx.Message)
{
case StartMessage:
tcs1.SetResult(ctx.Headers);
ctx.Send(probePid, ctx.Headers);
ctx.Request(pid1, new SomeRequest());

break;
case SomeResponse:
tcs2.SetResult(ctx.Headers);
ctx.Send(probePid, ctx.Headers);

break;
}
Expand All @@ -88,13 +88,13 @@ Sender PropagateHeaders(Sender next) =>

root.Send(pid2, new StartMessage());

//actor1 should have headers
var headers1 = await tcs1.Task.WithTimeout(TimeSpan.FromSeconds(5));
Assert.Equal(headers, headers1);

//actor2 should have headers
var headers2 = await tcs2.Task.WithTimeout(TimeSpan.FromSeconds(5));
Assert.Equal(headers, headers2);
await probe.ExpectNextUserMessageAsync<MessageHeader>(h => h.Equals(headers));

//actor2 should receive headers in the reply
await probe.ExpectNextUserMessageAsync<MessageHeader>(h => h.Equals(headers));

await probe.ExpectEmptyMailboxAsync();
}

[Fact]
Expand Down
Loading