Skip to content

Commit

Permalink
add tests for system shutdown (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing authored Oct 27, 2023
1 parent 07ef068 commit b06ae68
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/Proto.Actor.Tests/ActorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,76 @@ internal class MyAutoRespondMessage : IAutoRespond

public class ActorTests
{
[Fact]
public async Task CanNotSpawnAfterShutdown()
{
await using var system = new ActorSystem();
var context = system.Root;

PID SpawnActorFromFunc(Receive receive) => context.Spawn(Props.FromFunc(receive));

var pid = SpawnActorFromFunc(ctx =>
{
if (ctx.Message is string)
{
ctx.Respond("hey");
}
return Task.CompletedTask;
}
);

var reply = await context.RequestAsync<object>(pid, "hello");
Assert.Equal("hey", reply);

await system.ShutdownAsync();

var pid2 = SpawnActorFromFunc(ctx =>
{
if (ctx.Message is string)
{
ctx.Respond("hey");
}
return Task.CompletedTask;
}
);

Assert.Same(system.DeadLetterPid, pid2);
}

[Fact]
public async Task CanNotSendUserMessageAfterShutdown()
{
await using var system = new ActorSystem();
var context = system.Root;

PID SpawnActorFromFunc(Receive receive) => context.Spawn(Props.FromFunc(receive));

var pid = SpawnActorFromFunc(ctx =>
{
if (ctx.Message is string)
{
ctx.Respond("hey");
}
return Task.CompletedTask;
}
);

var reply = await context.RequestAsync<object>(pid, "hello");
Assert.Equal("hey", reply);

await system.ShutdownAsync();

//expect DeadLetterException

await Assert.ThrowsAsync<DeadLetterException>(async () =>
{
await context.RequestAsync<object>(pid, "hello");
});
}

[Fact]
public async Task RequestActorAsync()
{
Expand Down

0 comments on commit b06ae68

Please sign in to comment.