-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add WatchAysnc
methods for monitoring actor lifecycles outside of Akka.NET
#6102
Changes from all commits
f809aea
56abdd2
d435b48
a0fe12a
0013d1c
90eb11e
f36fe83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ public async Task GracefulStopShouldReturnTrueForAlreadyDeadActor() | |
|
||
private class CustomShutdown{} | ||
|
||
[Fact(DisplayName = "GracefulStop should return false if shutdown goes overtime", Skip = "GracefulStop currently throws a TaskCancellationException, which seems wrong")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enabled this spec as I went back and addressed this behavior |
||
[Fact(DisplayName = "GracefulStop should return false if shutdown goes overtime")] | ||
public async Task GracefulStopShouldThrowIfShutdownGoesOvertime() | ||
{ | ||
// arrange | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="WatchAsyncSpecs.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.TestKit; | ||
using Akka.TestKit.TestActors; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Akka.Tests.Actor | ||
{ | ||
public class WatchAsyncSpecs : AkkaSpec | ||
{ | ||
[Fact(DisplayName = "WatchAsync should return true when actor is terminated")] | ||
public async Task WatchAsync_should_return_true_when_actor_is_terminated() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy path use case test. |
||
{ | ||
// arrange | ||
var actor = Sys.ActorOf(BlackHoleActor.Props); | ||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)); | ||
var terminatedTask = actor.WatchAsync(cts.Token); | ||
|
||
// act | ||
Sys.Stop(actor); | ||
var terminated = await terminatedTask; | ||
|
||
// assert | ||
terminated.Should().BeTrue(); | ||
} | ||
|
||
[Fact(DisplayName = "WatchAsync should return true when called on actor that is already terminated")] | ||
public async Task WatchAsync_should_return_true_when_actor_is_already_terminated() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idempotent use case - watching an already dead actor. |
||
{ | ||
// arrange | ||
var actor = Sys.ActorOf(BlackHoleActor.Props); | ||
Watch(actor); | ||
Sys.Stop(actor); | ||
await ExpectTerminatedAsync(actor); | ||
|
||
// act | ||
|
||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3)); | ||
var terminated = await actor.WatchAsync(cts.Token); | ||
|
||
// assert | ||
terminated.Should().BeTrue(); | ||
} | ||
|
||
[Fact(DisplayName = "WatchAsync should return false when cancellation token is cancelled")] | ||
public async Task WatchAsync_should_return_true_when_cancelled() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Negative case - cancellation. |
||
{ | ||
// arrange | ||
var actor = Sys.ActorOf(BlackHoleActor.Props); | ||
using var cts = new CancellationTokenSource(); | ||
var terminatedTask = actor.WatchAsync(cts.Token); | ||
|
||
// act | ||
cts.Cancel(); | ||
var terminated = await terminatedTask; | ||
|
||
// assert | ||
terminated.Should().BeFalse(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a new extension method for working with
IActorRef