Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added `GracefulStop` specs * added one more use case * fixing up some buggy `ActorLifeCycleSpec`s
- Loading branch information
1 parent
4c2f30e
commit daa2b9b
Showing
2 changed files
with
82 additions
and
16 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
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,71 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="GracefulStopSpecs.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Actor.Dsl; | ||
using Akka.TestKit; | ||
using Akka.TestKit.TestActors; | ||
using Xunit; | ||
using FluentAssertions; | ||
|
||
namespace Akka.Tests.Actor | ||
{ | ||
public class GracefulStopSpecs : AkkaSpec | ||
{ | ||
[Fact(DisplayName = "GracefulStop should terminate target actor on-time")] | ||
public async Task GracefulStopShouldTerminateOnTime() | ||
{ | ||
// arrange | ||
var actor = Sys.ActorOf(BlackHoleActor.Props); | ||
Watch(actor); | ||
|
||
// act | ||
var stopped = await actor.GracefulStop(TimeSpan.FromSeconds(3)); | ||
await ExpectTerminatedAsync(actor); | ||
|
||
// assert | ||
stopped.Should().BeTrue(); | ||
} | ||
|
||
[Fact(DisplayName = "GracefulStop should return true for an already terminated actor")] | ||
public async Task GracefulStopShouldReturnTrueForAlreadyDeadActor() | ||
{ | ||
// arrange | ||
var actor = Sys.ActorOf(BlackHoleActor.Props); | ||
Watch(actor); | ||
|
||
// act | ||
Sys.Stop(actor); | ||
await ExpectTerminatedAsync(actor); | ||
var stopped = await actor.GracefulStop(TimeSpan.FromSeconds(3)); | ||
|
||
// assert | ||
stopped.Should().BeTrue(); | ||
} | ||
|
||
private class CustomShutdown{} | ||
|
||
[Fact(DisplayName = "GracefulStop should return false if shutdown goes overtime", Skip = "GracefulStop currently throws a TaskCancellationException, which seems wrong")] | ||
public async Task GracefulStopShouldThrowIfShutdownGoesOvertime() | ||
{ | ||
// arrange | ||
var actor = Sys.ActorOf(act => act.ReceiveAsync<CustomShutdown>(async (a, ctx) => | ||
{ | ||
await Task.Delay(200); | ||
ctx.Stop(ctx.Self); | ||
})); | ||
|
||
// act | ||
var stopped = await actor.GracefulStop(TimeSpan.FromMilliseconds(10), new CustomShutdown()); | ||
|
||
// assert | ||
stopped.Should().BeFalse(); | ||
} | ||
} | ||
} |