Table of Contents

Class TestKitBase

Namespace
Akka.TestKit
Assembly
Akka.TestKit.dll

Unless you're creating a TestKit for a specific test framework, you should probably not inherit directly from this class.

public abstract class TestKitBase : IActorRefFactory
Inheritance
TestKitBase
Implements
IActorRefFactory
Derived
Inherited Members

Constructors

TestKitBase(ITestKitAssertions, ActorSystem, ActorSystemSetup, string, string)

protected TestKitBase(ITestKitAssertions assertions, ActorSystem system, ActorSystemSetup config, string actorSystemName, string testActorName)

Parameters

assertions ITestKitAssertions
system ActorSystem
config ActorSystemSetup
actorSystemName string
testActorName string

TestKitBase(ITestKitAssertions, ActorSystem, string)

Create a new instance of the TestKitBase class. If no system is passed in, a new system with DefaultConfig will be created.

protected TestKitBase(ITestKitAssertions assertions, ActorSystem system = null, string testActorName = null)

Parameters

assertions ITestKitAssertions

The framework-specific assertion tools.

system ActorSystem

Optional: The actor system.

testActorName string

Optional: The name of the TestActor.

Exceptions

ArgumentNullException

This exception is thrown when the given assertions is undefined.

TestKitBase(ITestKitAssertions, ActorSystemSetup, string, string)

Create a new instance of the TestKitBase class. A new system with the specified configuration will be created.

protected TestKitBase(ITestKitAssertions assertions, ActorSystemSetup setup, string actorSystemName = null, string testActorName = null)

Parameters

assertions ITestKitAssertions

The set of assertions used by the TestKit.

setup ActorSystemSetup

The Akka.Actor.Setup.ActorSystemSetup to use for the configuring the system.

actorSystemName string

Optional: the name of the ActorSystem.

testActorName string

Optional: the name of the TestActor.

Exceptions

ArgumentNullException

This exception is thrown when the given assertions is undefined.

TestKitBase(ITestKitAssertions, Config, string, string)

Create a new instance of the TestKitBase class. A new system with the specified configuration will be created.

protected TestKitBase(ITestKitAssertions assertions, Config config, string actorSystemName = null, string testActorName = null)

Parameters

assertions ITestKitAssertions

The set of assertions used by the TestKit.

config Config

The configuration to use for the system.

actorSystemName string

Optional: the name of the ActorSystem.

testActorName string

Optional: the name of the TestActor.

Exceptions

ArgumentNullException

This exception is thrown when the given assertions is undefined.

Properties

DefaultConfig

The default TestKit configuration.

public static Config DefaultConfig { get; }

Property Value

Config

EventFilter

Filter Akka.Event.LogEvent sent to the system's Akka.Event.EventStream. In order to be able to filter the log the special logger TestEventListener must be installed using the config

akka.loggers = ["Akka.TestKit.TestEventListener, Akka.TestKit"]

It is installed by default in testkit.

public EventFilterFactory EventFilter { get; }

Property Value

EventFilterFactory

FullDebugConfig

A full debugging configuration with all log settings enabled.

public static Config FullDebugConfig { get; }

Property Value

Config

HasMessages

Returns true if messages are available.

public bool HasMessages { get; }

Property Value

bool

true if messages are available; otherwise, false.

LastMessage

The last message received by the TestActor.

public object LastMessage { get; }

Property Value

object

LastSender

The last Akka.Actor.IActorRef to send a message to the TestActor.

public IActorRef LastSender { get; }

Property Value

IActorRef

Log

The built-in Akka.Event.ILoggingAdapter used by Sys.

public ILoggingAdapter Log { get; }

Property Value

ILoggingAdapter

Now

The current time.

public static TimeSpan Now { get; }

Property Value

TimeSpan

Remaining

Retrieves the time remaining for execution of the innermost enclosing Within block.

The returned value is always finite.
public TimeSpan Remaining { get; }

Property Value

TimeSpan

Exceptions

InvalidOperationException

This exception is thrown when called from outside of within.

RemainingOrDefault

Retrieves the time remaining for execution of the innermost enclosing Within block. If missing that, then it returns the properly dilated default for this case from settings (key: "akka.test.single-expect-default").

The returned value is always finite.
public TimeSpan RemainingOrDefault { get; }

Property Value

TimeSpan

Sys

The Akka.Actor.ActorSystem that is recreated and used for each test.

public ActorSystem Sys { get; }

Property Value

ActorSystem

TestActor

The default TestActor. The actor can be controlled by sending it special control messages, see TestActor.SetIgnore, TestActor.Watch, TestActor.Unwatch. You can also install an AutoPilot to drive the actor, see SetAutoPilot(AutoPilot). All other messages are forwarded to the queue and can be retrieved with Receive and the ExpectMsg overloads.

public IActorRef TestActor { get; }

Property Value

IActorRef

TestKitSettings

The settings for the testkit.

public TestKitSettings TestKitSettings { get; }

Property Value

TestKitSettings

Methods

ActorOf(Props)

Create a new actor as child of Sys.

public IActorRef ActorOf(Props props)

Parameters

props Props

The props configuration object

Returns

IActorRef

TBD

ActorOf(Props, string)

Create a new actor as child of Sys.

public IActorRef ActorOf(Props props, string name)

Parameters

props Props

The props configuration object

name string

The name of the actor.

Returns

IActorRef

TBD

ActorOf(Action<IActorDsl, IActorContext>, string)

Creates a new actor by defining the behavior inside the configure action.

ActorOf(c =>
{
    c.Receive<string>((msg, ctx) => ctx.Sender.Tell("Hello " + msg));
});
public IActorRef ActorOf(Action<IActorDsl, IActorContext> configure, string name = null)

Parameters

configure Action<IActorDsl, IActorContext>

An action that configures the actor's behavior.

name string

Optional: The name of the actor.

Returns

IActorRef

TBD

ActorOf(Action<IActorDsl>, string)

Creates a new actor by defining the behavior inside the configure action.

ActorOf(c =>
{
    c.Receive<string>((msg, ctx) => ctx.Sender.Tell("Hello " + msg));
});
public IActorRef ActorOf(Action<IActorDsl> configure, string name = null)

Parameters

configure Action<IActorDsl>

An action that configures the actor's behavior.

name string

Optional: The name of the actor.

Returns

IActorRef

TBD

ActorOfAsTestActorRef<TActor>(IActorRef, string)

Create a new actor as child of the specified supervisor and returns it as TestActorRef<TActor> to enable access to the underlying actor instance via UnderlyingActor.

public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(IActorRef supervisor, string name = null) where TActor : ActorBase, new()

Parameters

supervisor IActorRef

The supervisor

name string

Optional: The name.

Returns

TestActorRef<TActor>

TBD

Type Parameters

TActor

The type of the actor. It must have a parameterless public constructor

ActorOfAsTestActorRef<TActor>(Props, IActorRef, string)

Create a new actor as child of specified supervisor and returns it as TestActorRef<TActor> to enable access to the underlying actor instance via UnderlyingActor.

public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(Props props, IActorRef supervisor, string name = null) where TActor : ActorBase

Parameters

props Props

The Akka.Actor.Props object

supervisor IActorRef

The supervisor

name string

Optional: The name.

Returns

TestActorRef<TActor>

TBD

Type Parameters

TActor

The type of the actor. It must have a parameterless public constructor

ActorOfAsTestActorRef<TActor>(Props, string)

Create a new actor as child of Sys and returns it as TestActorRef<TActor> to enable access to the underlying actor instance via UnderlyingActor.

public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(Props props, string name = null) where TActor : ActorBase

Parameters

props Props

The Akka.Actor.Props object

name string

Optional: The name.

Returns

TestActorRef<TActor>

TBD

Type Parameters

TActor

The type of the actor. It must have a parameterless public constructor

ActorOfAsTestActorRef<TActor>(Expression<Func<TActor>>, IActorRef, string)

Create a new actor as child of the specified supervisor and returns it as TestActorRef<TActor> to enable access to the underlying actor instance via UnderlyingActor. Uses an expression that calls the constructor of TActor.

ActorOf<MyActor>(()=>new MyActor("value", 4711), "test-actor")
public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(Expression<Func<TActor>> factory, IActorRef supervisor, string name = null) where TActor : ActorBase

Parameters

factory Expression<Func<TActor>>

An expression that calls the constructor of TActor

supervisor IActorRef

The supervisor

name string

Optional: The name.

Returns

TestActorRef<TActor>

TBD

Type Parameters

TActor

The type of the actor.

ActorOfAsTestActorRef<TActor>(Expression<Func<TActor>>, string)

Create a new actor as child of Sys and returns it as TestActorRef<TActor> to enable access to the underlying actor instance via UnderlyingActor. Uses an expression that calls the constructor of TActor.

ActorOf<MyActor>(()=>new MyActor("value", 4711), "test-actor")
public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(Expression<Func<TActor>> factory, string name = null) where TActor : ActorBase

Parameters

factory Expression<Func<TActor>>

An expression that calls the constructor of TActor

name string

Optional: The name.

Returns

TestActorRef<TActor>

TBD

Type Parameters

TActor

The type of the actor.

ActorOfAsTestActorRef<TActor>(string)

Create a new actor as child of Sys and returns it as TestActorRef<TActor> to enable access to the underlying actor instance via UnderlyingActor.

public TestActorRef<TActor> ActorOfAsTestActorRef<TActor>(string name = null) where TActor : ActorBase, new()

Parameters

name string

Optional: The name.

Returns

TestActorRef<TActor>

TBD

Type Parameters

TActor

The type of the actor. It must have a parameterless public constructor

ActorOfAsTestFSMRef<TFsmActor, TState, TData>(IActorRef, string, bool)

Create a new Akka.Actor.FSM`2 as child of the specified supervisor and returns it as TestFSMRef<TActor, TState, TData> to enable inspecting and modifying the FSM directly. TFsmActor must have a public parameterless constructor.

public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(IActorRef supervisor, string name = null, bool withLogging = false) where TFsmActor : FSM<TState, TData>, new()

Parameters

supervisor IActorRef

The supervisor

name string

Optional: The name.

withLogging bool

Optional: If set to true logs state changes of the FSM as Debug messages. Default is false.

Returns

TestFSMRef<TFsmActor, TState, TData>

TBD

Type Parameters

TFsmActor

The type of the actor. It must have a parameterless public constructor

TState

The type of state name

TData

The type of state data

ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Props, IActorRef, string, bool)

Create a new Akka.Actor.FSM`2 as child of the specified supervisor and returns it as TestFSMRef<TActor, TState, TData> to enable inspecting and modifying the FSM directly.

public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Props props, IActorRef supervisor, string name = null, bool withLogging = false) where TFsmActor : FSM<TState, TData>

Parameters

props Props

The Akka.Actor.Props object

supervisor IActorRef

The supervisor

name string

Optional: The name.

withLogging bool

Optional: If set to true logs state changes of the FSM as Debug messages. Default is false.

Returns

TestFSMRef<TFsmActor, TState, TData>

TBD

Type Parameters

TFsmActor

The type of the actor. It must be a Akka.Actor.FSM`2

TState

The type of state name

TData

The type of state data

ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Props, string, bool)

Create a new Akka.Actor.FSM`2 as child of Sys and returns it as TestFSMRef<TActor, TState, TData> to enable inspecting and modifying the FSM directly.

public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Props props, string name = null, bool withLogging = false) where TFsmActor : FSM<TState, TData>

Parameters

props Props

The Akka.Actor.Props object

name string

Optional: The name.

withLogging bool

Optional: If set to true logs state changes of the FSM as Debug messages. Default is false.

Returns

TestFSMRef<TFsmActor, TState, TData>

TBD

Type Parameters

TFsmActor

The type of the actor. It must be a Akka.Actor.FSM`2 and have a public parameterless constructor

TState

The type of state name

TData

The type of state data

ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Expression<Func<TFsmActor>>, IActorRef, string, bool)

Create a new Akka.Actor.FSM`2 as child of the specified supervisor and returns it as TestFSMRef<TActor, TState, TData> to enable inspecting and modifying the FSM directly. Uses an expression that calls the constructor of TFsmActor.

public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Expression<Func<TFsmActor>> factory, IActorRef supervisor, string name = null, bool withLogging = false) where TFsmActor : FSM<TState, TData>

Parameters

factory Expression<Func<TFsmActor>>

An expression that calls the constructor of TFsmActor

supervisor IActorRef

The supervisor

name string

Optional: The name.

withLogging bool

Optional: If set to true logs state changes of the FSM as Debug messages. Default is false.

Returns

TestFSMRef<TFsmActor, TState, TData>

TBD

Type Parameters

TFsmActor

The type of the actor.

TState

The type of state name

TData

The type of state data

ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Expression<Func<TFsmActor>>, string, bool)

Create a new Akka.Actor.FSM`2 as child of Sys and returns it as TestFSMRef<TActor, TState, TData> to enable inspecting and modifying the FSM directly. Uses an expression that calls the constructor of TFsmActor.

public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(Expression<Func<TFsmActor>> factory, string name = null, bool withLogging = false) where TFsmActor : FSM<TState, TData>

Parameters

factory Expression<Func<TFsmActor>>

An expression that calls the constructor of TFsmActor

name string

Optional: The name.

withLogging bool

Optional: If set to true logs state changes of the FSM as Debug messages. Default is false.

Returns

TestFSMRef<TFsmActor, TState, TData>

TBD

Type Parameters

TFsmActor

The type of the actor.

TState

The type of state name

TData

The type of state data

ActorOfAsTestFSMRef<TFsmActor, TState, TData>(string, bool)

Create a new Akka.Actor.FSM`2 as child of Sys and returns it as TestFSMRef<TActor, TState, TData> to enable inspecting and modifying the FSM directly. TFsmActor must have a public parameterless constructor.

public TestFSMRef<TFsmActor, TState, TData> ActorOfAsTestFSMRef<TFsmActor, TState, TData>(string name = null, bool withLogging = false) where TFsmActor : FSM<TState, TData>, new()

Parameters

name string

Optional: The name.

withLogging bool

Optional: If set to true logs state changes of the FSM as Debug messages. Default is false.

Returns

TestFSMRef<TFsmActor, TState, TData>

TBD

Type Parameters

TFsmActor

The type of the actor. It must have a parameterless public constructor

TState

The type of state name

TData

The type of state data

ActorOf<TActor>()

Create a new actor as child of Sys.

public IActorRef ActorOf<TActor>() where TActor : ActorBase, new()

Returns

IActorRef

TBD

Type Parameters

TActor

The type of the actor. It must have a parameterless public constructor

ActorOf<TActor>(Expression<Func<TActor>>)

Create a new actor as child of Sys using an expression that calls the constructor of TActor.

ActorOf<MyActor>(()=>new MyActor("value", 4711))
public IActorRef ActorOf<TActor>(Expression<Func<TActor>> factory) where TActor : ActorBase

Parameters

factory Expression<Func<TActor>>

An expression that calls the constructor of TActor

Returns

IActorRef

TBD

Type Parameters

TActor

The type of the actor.

ActorOf<TActor>(Expression<Func<TActor>>, string)

Create a new actor as child of Sys using an expression that calls the constructor of TActor.

ActorOf<MyActor>(()=>new MyActor("value", 4711), "test-actor")
public IActorRef ActorOf<TActor>(Expression<Func<TActor>> factory, string name) where TActor : ActorBase

Parameters

factory Expression<Func<TActor>>

An expression that calls the constructor of TActor

name string

The name of the actor.

Returns

IActorRef

TBD

Type Parameters

TActor

The type of the actor.

ActorOf<TActor>(string)

Create a new actor as child of Sys.

public IActorRef ActorOf<TActor>(string name) where TActor : ActorBase, new()

Parameters

name string

The name of the actor.

Returns

IActorRef

TBD

Type Parameters

TActor

The type of the actor. It must have a parameterless public constructor

ActorSelection(ActorPath)

public ActorSelection ActorSelection(ActorPath actorPath)

Parameters

actorPath ActorPath

The path of the actor(s) we want to select.

Returns

ActorSelection

An ActorSelection

ActorSelection(IActorRef, string)

public ActorSelection ActorSelection(IActorRef anchorRef, string actorPath)

Parameters

anchorRef IActorRef

The base actor that anchors the actorPath.

actorPath string

The path of the actor(s) we want to select.

Returns

ActorSelection

An ActorSelection

ActorSelection(string)

public ActorSelection ActorSelection(string actorPath)

Parameters

actorPath string

The path of the actor(s) we want to select.

Returns

ActorSelection

An ActorSelection

AwaitAssert(Action, TimeSpan?, TimeSpan?, CancellationToken)

Await until the given assertion does not throw an exception or the timeout expires, whichever comes first. If the timeout expires the last exception is thrown.

The action is called, and if it throws an exception the thread sleeps the specified interval before retrying.

If no timeout is given, take it from the innermost enclosing `within` block.

Note that the timeout is scaled using Dilated(TimeSpan), which uses the configuration entry "akka.test.timefactor".

public void AwaitAssert(Action assertion, TimeSpan? duration = null, TimeSpan? interval = null, CancellationToken cancellationToken = default)

Parameters

assertion Action

The action.

duration TimeSpan?

The timeout.

interval TimeSpan?

The interval to wait between executing the assertion.

cancellationToken CancellationToken

AwaitAssertAsync(Action, TimeSpan?, TimeSpan?, CancellationToken)

public Task AwaitAssertAsync(Action assertion, TimeSpan? duration = null, TimeSpan? interval = null, CancellationToken cancellationToken = default)

Parameters

assertion Action
duration TimeSpan?
interval TimeSpan?
cancellationToken CancellationToken

Returns

Task

AwaitAssertAsync(Func<Task>, TimeSpan?, TimeSpan?, CancellationToken)

Await until the given assertion does not throw an exception or the timeout expires, whichever comes first. If the timeout expires the last exception is thrown.

The action is called, and if it throws an exception the thread sleeps the specified interval before retrying.

If no timeout is given, take it from the innermost enclosing `within` block.

Note that the timeout is scaled using Dilated(TimeSpan), which uses the configuration entry "akka.test.timefactor".

public Task AwaitAssertAsync(Func<Task> assertion, TimeSpan? duration = null, TimeSpan? interval = null, CancellationToken cancellationToken = default)

Parameters

assertion Func<Task>

The action.

duration TimeSpan?

The timeout.

interval TimeSpan?

The interval to wait between executing the assertion.

cancellationToken CancellationToken

Returns

Task

AwaitCondition(Func<bool>, TimeSpan?, TimeSpan?, string, CancellationToken)

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing `within` block.

Note that the timeout is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor".

The parameter interval specifies the time between calls to conditionIsFulfilled Between calls the thread sleeps. If interval is undefined the thread only sleeps one time, using the max as duration, and then rechecks the condition and ultimately succeeds or fails.

To make sure that tests run as fast as possible, make sure you do not leave this value as undefined, instead set it to a relatively small value.

public void AwaitCondition(Func<bool> conditionIsFulfilled, TimeSpan? max, TimeSpan? interval, string message = null, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>

The condition that must be fulfilled within the duration.

max TimeSpan?

The maximum duration. If undefined, uses the remaining time (if inside a within block) or the value specified in config value "akka.test.single-expect-default". The value is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor".

interval TimeSpan?

The time between calls to conditionIsFulfilled to check if the condition is fulfilled. Between calls the thread sleeps. If undefined, negative or InfiniteTimeSpanthe thread only sleeps one time, using the max, and then rechecks the condition and ultimately succeeds or fails.

To make sure that tests run as fast as possible, make sure you do not set this value as undefined, instead set it to a relatively small value.

message string

The message used if the timeout expires.

cancellationToken CancellationToken

AwaitCondition(Func<bool>, TimeSpan?, string, CancellationToken)

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing `within` block (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". The value is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor"..

A call to conditionIsFulfilled is done immediately, then the threads sleep for about a tenth of the timeout value, before it checks the condition again. This is repeated until timeout or the condition evaluates to true. To specify another interval, use the overload AwaitCondition(Func<bool>, TimeSpan?, TimeSpan?, string, CancellationToken)

public void AwaitCondition(Func<bool> conditionIsFulfilled, TimeSpan? max, string message, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>

The condition that must be fulfilled within the duration.

max TimeSpan?

The maximum duration. If undefined, uses the remaining time (if inside a within block) or the value specified in config value "akka.test.single-expect-default". The value is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor".

message string

The message used if the timeout expires.

cancellationToken CancellationToken

AwaitCondition(Func<bool>, TimeSpan?, CancellationToken)

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing `within` block (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". The value is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor"..

A call to conditionIsFulfilled is done immediately, then the threads sleep for about a tenth of the timeout value, before it checks the condition again. This is repeated until timeout or the condition evaluates to true. To specify another interval, use the overload AwaitCondition(Func<bool>, TimeSpan?, TimeSpan?, string, CancellationToken)

public void AwaitCondition(Func<bool> conditionIsFulfilled, TimeSpan? max, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>

The condition that must be fulfilled within the duration.

max TimeSpan?

The maximum duration. If undefined, uses the remaining time (if inside a within block) or the value specified in config value "akka.test.single-expect-default". The value is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor".

cancellationToken CancellationToken

AwaitCondition(Func<bool>, CancellationToken)

Await until the given condition evaluates to true or until a timeout

The timeout is taken from the innermost enclosing `within` block (if inside a `within` block) or the value specified in config value "akka.test.single-expect-default". The value is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor"..

A call to conditionIsFulfilled is done immediately, then the threads sleep for about a tenth of the timeout value, before it checks the condition again. This is repeated until timeout or the condition evaluates to true. To specify another interval, use the overload AwaitCondition(Func<bool>, TimeSpan?, TimeSpan?, string, CancellationToken)

public void AwaitCondition(Func<bool> conditionIsFulfilled, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>

The condition that must be fulfilled within the duration.

cancellationToken CancellationToken

AwaitConditionAsync(Func<bool>, TimeSpan?, TimeSpan?, string, CancellationToken)

public Task AwaitConditionAsync(Func<bool> conditionIsFulfilled, TimeSpan? max, TimeSpan? interval, string message = null, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>
max TimeSpan?
interval TimeSpan?
message string
cancellationToken CancellationToken

Returns

Task

AwaitConditionAsync(Func<bool>, TimeSpan?, string, CancellationToken)

public Task AwaitConditionAsync(Func<bool> conditionIsFulfilled, TimeSpan? max, string message, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>
max TimeSpan?
message string
cancellationToken CancellationToken

Returns

Task

AwaitConditionAsync(Func<bool>, CancellationToken)

public Task AwaitConditionAsync(Func<bool> conditionIsFulfilled, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>
cancellationToken CancellationToken

Returns

Task

AwaitConditionAsync(Func<Task<bool>>, TimeSpan?, TimeSpan?, string, CancellationToken)

public Task AwaitConditionAsync(Func<Task<bool>> conditionIsFulfilled, TimeSpan? max, TimeSpan? interval, string message = null, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<Task<bool>>
max TimeSpan?
interval TimeSpan?
message string
cancellationToken CancellationToken

Returns

Task

AwaitConditionAsync(Func<Task<bool>>, TimeSpan?, string, CancellationToken)

public Task AwaitConditionAsync(Func<Task<bool>> conditionIsFulfilled, TimeSpan? max, string message, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<Task<bool>>
max TimeSpan?
message string
cancellationToken CancellationToken

Returns

Task

AwaitConditionAsync(Func<Task<bool>>, TimeSpan?, CancellationToken)

public Task AwaitConditionAsync(Func<Task<bool>> conditionIsFulfilled, TimeSpan? max, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<Task<bool>>
max TimeSpan?
cancellationToken CancellationToken

Returns

Task

AwaitConditionAsync(Func<Task<bool>>, CancellationToken)

public Task AwaitConditionAsync(Func<Task<bool>> conditionIsFulfilled, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<Task<bool>>
cancellationToken CancellationToken

Returns

Task

AwaitConditionNoThrow(Func<bool>, TimeSpan, TimeSpan?, CancellationToken)

Await until the given condition evaluates to true or the timeout expires, whichever comes first. Returns true if the condition was fulfilled.

The parameter interval specifies the time between calls to conditionIsFulfilled Between calls the thread sleeps. If interval is not specified or null 100 ms is used.

public bool AwaitConditionNoThrow(Func<bool> conditionIsFulfilled, TimeSpan max, TimeSpan? interval = null, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>

The condition that must be fulfilled within the duration.

max TimeSpan

The maximum duration.

interval TimeSpan?

Optional. The time between calls to conditionIsFulfilled to check if the condition is fulfilled. Between calls the thread sleeps. If undefined, 100 ms is used

cancellationToken CancellationToken

Returns

bool

TBD

AwaitConditionNoThrowAsync(Func<bool>, TimeSpan, TimeSpan?, CancellationToken)

public Task<bool> AwaitConditionNoThrowAsync(Func<bool> conditionIsFulfilled, TimeSpan max, TimeSpan? interval = null, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>
max TimeSpan
interval TimeSpan?
cancellationToken CancellationToken

Returns

Task<bool>

AwaitConditionNoThrowAsync(Func<Task<bool>>, TimeSpan, TimeSpan?, CancellationToken)

public Task<bool> AwaitConditionNoThrowAsync(Func<Task<bool>> conditionIsFulfilled, TimeSpan max, TimeSpan? interval = null, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<Task<bool>>
max TimeSpan
interval TimeSpan?
cancellationToken CancellationToken

Returns

Task<bool>

ChildActorOf(Props, SupervisorStrategy, CancellationToken)

Spawns an actor as a child of this test actor with an auto-generated name, and returns the child's ActorRef.

public IActorRef ChildActorOf(Props props, SupervisorStrategy supervisorStrategy, CancellationToken cancellationToken = default)

Parameters

props Props

Child actor props

supervisorStrategy SupervisorStrategy

Supervisor strategy for the child actor

cancellationToken CancellationToken

CancellationToken to cancel the operation

Returns

IActorRef

ChildActorOf(Props, string, SupervisorStrategy, CancellationToken)

Spawns an actor as a child of this test actor, and returns the child's IActorRef

public IActorRef ChildActorOf(Props props, string name, SupervisorStrategy supervisorStrategy, CancellationToken cancellationToken = default)

Parameters

props Props

Child actor props

name string

Child actor name

supervisorStrategy SupervisorStrategy

Supervisor strategy for the child actor

cancellationToken CancellationToken

CancellationToken to cancel the operation

Returns

IActorRef

ChildActorOf(Props, string, CancellationToken)

Spawns an actor as a child of this test actor with a stopping supervisor strategy, and returns the child's ActorRef.

public IActorRef ChildActorOf(Props props, string name, CancellationToken cancellationToken = default)

Parameters

props Props

Child actor props

name string

Child actor name

cancellationToken CancellationToken

CancellationToken to cancel the operation

Returns

IActorRef

ChildActorOf(Props, CancellationToken)

Spawns an actor as a child of this test actor with an auto-generated name and stopping supervisor strategy, returning the child's ActorRef.

public IActorRef ChildActorOf(Props props, CancellationToken cancellationToken = default)

Parameters

props Props

Child actor props

cancellationToken CancellationToken

CancellationToken to cancel the operation

Returns

IActorRef

ChildActorOfAsync(Props, SupervisorStrategy, CancellationToken)

Spawns an actor as a child of this test actor with an auto-generated name, and returns the child's ActorRef.

public Task<IActorRef> ChildActorOfAsync(Props props, SupervisorStrategy supervisorStrategy, CancellationToken cancellationToken = default)

Parameters

props Props

Child actor props

supervisorStrategy SupervisorStrategy

Supervisor strategy for the child actor

cancellationToken CancellationToken

CancellationToken to cancel the operation

Returns

Task<IActorRef>

ChildActorOfAsync(Props, string, SupervisorStrategy, CancellationToken)

Spawns an actor as a child of this test actor, and returns the child's IActorRef

public Task<IActorRef> ChildActorOfAsync(Props props, string name, SupervisorStrategy supervisorStrategy, CancellationToken cancellationToken = default)

Parameters

props Props

Child actor props

name string

Child actor name

supervisorStrategy SupervisorStrategy

Supervisor strategy for the child actor

cancellationToken CancellationToken

CancellationToken to cancel the operation

Returns

Task<IActorRef>

ChildActorOfAsync(Props, string, CancellationToken)

Spawns an actor as a child of this test actor with a stopping supervisor strategy, and returns the child's ActorRef.

public Task<IActorRef> ChildActorOfAsync(Props props, string name, CancellationToken cancellationToken = default)

Parameters

props Props

Child actor props

name string

Child actor name

cancellationToken CancellationToken

CancellationToken to cancel the operation

Returns

Task<IActorRef>

ChildActorOfAsync(Props, CancellationToken)

Spawns an actor as a child of this test actor with an auto-generated name and stopping supervisor strategy, returning the child's ActorRef.

public Task<IActorRef> ChildActorOfAsync(Props props, CancellationToken cancellationToken = default)

Parameters

props Props

Child actor props

cancellationToken CancellationToken

CancellationToken to cancel the operation

Returns

Task<IActorRef>

CreateEventFilter(ActorSystem)

Creates a new event filter for the specified actor system.

public EventFilterFactory CreateEventFilter(ActorSystem system)

Parameters

system ActorSystem

Actor system.

Returns

EventFilterFactory

A new instance of EventFilterFactory.

CreateTestActor(string)

Creates a test actor with the specified name. The actor can be controlled by sending it special control messages, see TestActor.SetIgnore, TestActor.Watch, TestActor.Unwatch, TestActor.SetAutoPilot. All other messages are forwarded to the queue and can be retrieved with Receive and the ExpectMsg overloads.

The default test actor can be retrieved from the TestActor property

public IActorRef CreateTestActor(string name)

Parameters

name string

The name of the new actor.

Returns

IActorRef

TBD

CreateTestBarrier(int)

Wraps a Barrier for use in testing. It always uses a timeout when waiting. Timeouts will always throw an exception. The default timeout is 5 seconds.

public TestBarrier CreateTestBarrier(int count)

Parameters

count int

TBD

Returns

TestBarrier

TBD

CreateTestLatch(int)

Creates a Countdown latch wrapper for use in testing.

It uses a timeout when waiting and timeouts are specified as durations. There's a default timeout of 5 seconds and the default count is 1. Timeouts will always throw an exception.

public virtual TestLatch CreateTestLatch(int count = 1)

Parameters

count int

Optional. The count. Default: 1

Returns

TestLatch

A new TestLatch

CreateTestProbe(ActorSystem, string)

Creates a new TestProbe.

public virtual TestProbe CreateTestProbe(ActorSystem system, string name = null)

Parameters

system ActorSystem

For multi-actor system tests, you can specify which system the node is for.

name string

Optional: The name of the probe.

Returns

TestProbe

TBD

CreateTestProbe(string)

Creates a new TestProbe.

public virtual TestProbe CreateTestProbe(string name = null)

Parameters

name string

Optional: The name of the probe.

Returns

TestProbe

A new TestProbe instance.

Dilated(TimeSpan)

Multiplies the duration with the TestTimeFactor, i.e. the config value "akka.test.timefactor"

public TimeSpan Dilated(TimeSpan duration)

Parameters

duration TimeSpan

TBD

Returns

TimeSpan

TBD

ExpectMsgAllOfAsync<T>(IReadOnlyCollection<T>, CancellationToken)

public IAsyncEnumerable<T> ExpectMsgAllOfAsync<T>(IReadOnlyCollection<T> messages, CancellationToken cancellationToken = default)

Parameters

messages IReadOnlyCollection<T>
cancellationToken CancellationToken

Returns

IAsyncEnumerable<T>

Type Parameters

T

ExpectMsgAllOfAsync<T>(TimeSpan, IReadOnlyCollection<T>, CancellationToken)

public IAsyncEnumerable<T> ExpectMsgAllOfAsync<T>(TimeSpan max, IReadOnlyCollection<T> messages, CancellationToken cancellationToken = default)

Parameters

max TimeSpan
messages IReadOnlyCollection<T>
cancellationToken CancellationToken

Returns

IAsyncEnumerable<T>

Type Parameters

T

ExpectMsgAllOfMatchingPredicates(params PredicateInfo[])

public IReadOnlyCollection<object> ExpectMsgAllOfMatchingPredicates(params PredicateInfo[] predicates)

Parameters

predicates PredicateInfo[]

Returns

IReadOnlyCollection<object>

ExpectMsgAllOfMatchingPredicates(IReadOnlyCollection<PredicateInfo>, CancellationToken)

public IReadOnlyCollection<object> ExpectMsgAllOfMatchingPredicates(IReadOnlyCollection<PredicateInfo> predicates, CancellationToken cancellationToken)

Parameters

predicates IReadOnlyCollection<PredicateInfo>
cancellationToken CancellationToken

Returns

IReadOnlyCollection<object>

ExpectMsgAllOfMatchingPredicates(TimeSpan, params PredicateInfo[])

public IReadOnlyCollection<object> ExpectMsgAllOfMatchingPredicates(TimeSpan max, params PredicateInfo[] predicates)

Parameters

max TimeSpan
predicates PredicateInfo[]

Returns

IReadOnlyCollection<object>

ExpectMsgAllOfMatchingPredicates(TimeSpan, IReadOnlyCollection<PredicateInfo>, CancellationToken)

public IReadOnlyCollection<object> ExpectMsgAllOfMatchingPredicates(TimeSpan max, IReadOnlyCollection<PredicateInfo> predicates, CancellationToken cancellationToken)

Parameters

max TimeSpan
predicates IReadOnlyCollection<PredicateInfo>
cancellationToken CancellationToken

Returns

IReadOnlyCollection<object>

ExpectMsgAllOfMatchingPredicatesAsync(IReadOnlyCollection<PredicateInfo>, CancellationToken)

public IAsyncEnumerable<object> ExpectMsgAllOfMatchingPredicatesAsync(IReadOnlyCollection<PredicateInfo> predicates, CancellationToken cancellationToken = default)

Parameters

predicates IReadOnlyCollection<PredicateInfo>
cancellationToken CancellationToken

Returns

IAsyncEnumerable<object>

ExpectMsgAllOfMatchingPredicatesAsync(TimeSpan, IReadOnlyCollection<PredicateInfo>, CancellationToken)

public IAsyncEnumerable<object> ExpectMsgAllOfMatchingPredicatesAsync(TimeSpan max, IReadOnlyCollection<PredicateInfo> predicates, CancellationToken cancellationToken = default)

Parameters

max TimeSpan
predicates IReadOnlyCollection<PredicateInfo>
cancellationToken CancellationToken

Returns

IAsyncEnumerable<object>

ExpectMsgAllOf<T>(IReadOnlyCollection<T>, CancellationToken)

Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa. This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by RemainingOrDefault as duration, with an assertion exception being thrown in case of timeout.

dispatcher.Tell(SomeWork1())
dispatcher.Tell(SomeWork2())
ExpectMsgAllOf(TimeSpan.FromSeconds(1), Result1(), Result2())
public IReadOnlyCollection<T> ExpectMsgAllOf<T>(IReadOnlyCollection<T> messages, CancellationToken cancellationToken = default)

Parameters

messages IReadOnlyCollection<T>

The messages.

cancellationToken CancellationToken

Returns

IReadOnlyCollection<T>

The received messages in received order

Type Parameters

T

The type of the messages

ExpectMsgAllOf<T>(TimeSpan, IReadOnlyCollection<T>, CancellationToken)

Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa. This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an assertion exception being thrown in case of timeout.

dispatcher.Tell(SomeWork1())
dispatcher.Tell(SomeWork2())
ExpectMsgAllOf(TimeSpan.FromSeconds(1), Result1(), Result2())

The deadline is scaled by "akka.test.timefactor" using Dilated(TimeSpan).

public IReadOnlyCollection<T> ExpectMsgAllOf<T>(TimeSpan max, IReadOnlyCollection<T> messages, CancellationToken cancellationToken = default)

Parameters

max TimeSpan

The deadline. The deadline is scaled by "akka.test.timefactor" using Dilated(TimeSpan).

messages IReadOnlyCollection<T>

The messages.

cancellationToken CancellationToken

Returns

IReadOnlyCollection<T>

The received messages in received order

Type Parameters

T

The type of the messages

ExpectMsgAllOf<T>(TimeSpan, params T[])

public IReadOnlyCollection<T> ExpectMsgAllOf<T>(TimeSpan max, params T[] messages)

Parameters

max TimeSpan
messages T[]

Returns

IReadOnlyCollection<T>

Type Parameters

T

ExpectMsgAllOf<T>(params T[])

public IReadOnlyCollection<T> ExpectMsgAllOf<T>(params T[] messages)

Parameters

messages T[]

Returns

IReadOnlyCollection<T>

Type Parameters

T

ExpectMsgAnyOfAsync<T>(IEnumerable<T>, CancellationToken)

public ValueTask<T> ExpectMsgAnyOfAsync<T>(IEnumerable<T> messages, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<T>
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgAnyOf<T>(IEnumerable<T>, CancellationToken)

Receive a message from the test actor and assert that it equals one of the given messages. Wait time is bounded by RemainingOrDefault as duration, with an assertion exception being thrown in case of timeout.

public T ExpectMsgAnyOf<T>(IEnumerable<T> messages, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<T>

The messages.

cancellationToken CancellationToken

Returns

T

The received messages in received order

Type Parameters

T

The type of the messages

ExpectMsgAsync<T>(Action<T, IActorRef>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgAsync<T>(Action<T, IActorRef> assertMessageAndSender, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

assertMessageAndSender Action<T, IActorRef>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgAsync<T>(Action<T>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgAsync<T>(Action<T> assert, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

assert Action<T>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgAsync<T>(Func<T, IActorRef, bool>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgAsync<T>(Func<T, IActorRef, bool> isMessageAndSender, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

isMessageAndSender Func<T, IActorRef, bool>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgAsync<T>(TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgAsync<T>(TimeSpan? duration = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

duration TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgAsync<T>(Predicate<T>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgAsync<T>(Predicate<T> isMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

isMessage Predicate<T>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgAsync<T>(T, Func<T, T, bool>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgAsync<T>(T expected, Func<T, T, bool> comparer, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

expected T
comparer Func<T, T, bool>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgAsync<T>(T, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgAsync<T>(T message, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

message T
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgFromAsync<T>(IActorRef, Action<T>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgFromAsync<T>(IActorRef sender, Action<T> assertMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

sender IActorRef
assertMessage Action<T>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgFromAsync<T>(IActorRef, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgFromAsync<T>(IActorRef sender, TimeSpan? duration = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

sender IActorRef
duration TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgFromAsync<T>(IActorRef, Predicate<T>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgFromAsync<T>(IActorRef sender, Predicate<T> isMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

sender IActorRef
isMessage Predicate<T>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgFromAsync<T>(IActorRef, T, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgFromAsync<T>(IActorRef sender, T message, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

sender IActorRef
message T
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgFromAsync<T>(Action<IActorRef>, Action<T>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgFromAsync<T>(Action<IActorRef> assertSender, Action<T> assertMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

assertSender Action<IActorRef>
assertMessage Action<T>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgFromAsync<T>(Predicate<IActorRef>, Predicate<T>, TimeSpan?, string, CancellationToken)

public ValueTask<T> ExpectMsgFromAsync<T>(Predicate<IActorRef> isSender, Predicate<T> isMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

isSender Predicate<IActorRef>
isMessage Predicate<T>
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

ExpectMsgFrom<T>(IActorRef, Action<T>, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor, verifies that the sender is the specified and calls the action that performs extra assertions. Wait time is bounded by the given duration if specified. If not specified, wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default". Use this variant to implement more complicated or conditional processing.

public T ExpectMsgFrom<T>(IActorRef sender, Action<T> assertMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

sender IActorRef

TBD

assertMessage Action<T>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsgFrom<T>(IActorRef, TimeSpan?, string, CancellationToken)

Receive one message from the test actor and assert that it is of the specified type and was sent by the specified sender Wait time is bounded by the given duration if specified. If not specified, wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsgFrom<T>(IActorRef sender, TimeSpan? duration = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

sender IActorRef

TBD

duration TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsgFrom<T>(IActorRef, Predicate<T>, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor and assert that the given predicate accepts it and was sent by the specified sender Wait time is bounded by the given duration if specified. If not specified, wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default". Use this variant to implement more complicated or conditional processing.

public T ExpectMsgFrom<T>(IActorRef sender, Predicate<T> isMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

sender IActorRef

TBD

isMessage Predicate<T>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsgFrom<T>(IActorRef, T, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor and assert that it equals the message and was sent by the specified sender Wait time is bounded by the given duration if specified. If not specified, wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsgFrom<T>(IActorRef sender, T message, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

sender IActorRef

TBD

message T

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsgFrom<T>(Action<IActorRef>, Action<T>, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor and calls the action that performs extra assertions. Wait time is bounded by the given duration if specified. If not specified, wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default". Use this variant to implement more complicated or conditional processing.

public T ExpectMsgFrom<T>(Action<IActorRef> assertSender, Action<T> assertMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

assertSender Action<IActorRef>

TBD

assertMessage Action<T>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsgFrom<T>(Predicate<IActorRef>, Predicate<T>, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor and assert that the given predicate accepts it and was sent by a sender that matches the isSender predicate. Wait time is bounded by the given duration if specified. If not specified, wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default". Use this variant to implement more complicated or conditional processing.

public T ExpectMsgFrom<T>(Predicate<IActorRef> isSender, Predicate<T> isMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

isSender Predicate<IActorRef>

TBD

isMessage Predicate<T>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsg<T>(Action<T, IActorRef>, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor calls the action that performs extra assertions. Use this variant to implement more complicated or conditional processing.

Wait time is bounded by the given duration, if specified; otherwise wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsg<T>(Action<T, IActorRef> assertMessageAndSender, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

assertMessageAndSender Action<T, IActorRef>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsg<T>(Action<T>, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor and calls the action that performs extra assertions. Use this variant to implement more complicated or conditional processing.

Wait time is bounded by the given duration, if specified; otherwise wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsg<T>(Action<T> assert, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

assert Action<T>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsg<T>(Func<T, IActorRef, bool>, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor and assert that the given predicate accepts it. Use this variant to implement more complicated or conditional processing.

Wait time is bounded by the given duration, if specified; otherwise wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsg<T>(Func<T, IActorRef, bool> isMessageAndSender, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

isMessageAndSender Func<T, IActorRef, bool>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsg<T>(TimeSpan?, string, CancellationToken)

Receive one message from the test actor and assert that it is of the specified type. Wait time is bounded by the given duration, if specified; otherwise wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsg<T>(TimeSpan? duration = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

duration TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsg<T>(Predicate<T>, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor and assert that the given predicate accepts it. Use this variant to implement more complicated or conditional processing.

Wait time is bounded by the given duration, if specified; otherwise wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsg<T>(Predicate<T> isMessage, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

isMessage Predicate<T>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsg<T>(T, Func<T, T, bool>, TimeSpan?, string, CancellationToken)

Receive one message from the test actor and assert that it is equal to the expected value, according to the specified comparer function.

Wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsg<T>(T expected, Func<T, T, bool> comparer, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

expected T

TBD

comparer Func<T, T, bool>

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectMsg<T>(T, TimeSpan?, string, CancellationToken)

Receive one message of the specified type from the test actor and assert that it equals the message. Wait time is bounded by the given duration, if specified; otherwise wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public T ExpectMsg<T>(T message, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

message T

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

ExpectNoMsg(int, CancellationToken)

Assert that no message is received for the specified time in milliseconds.

public void ExpectNoMsg(int milliseconds, CancellationToken cancellationToken = default)

Parameters

milliseconds int

TBD

cancellationToken CancellationToken

ExpectNoMsg(CancellationToken)

Assert that no message is received.

Wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public void ExpectNoMsg(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

ExpectNoMsg(TimeSpan, CancellationToken)

Assert that no message is received for the specified time.

public void ExpectNoMsg(TimeSpan duration, CancellationToken cancellationToken = default)

Parameters

duration TimeSpan

TBD

cancellationToken CancellationToken

ExpectNoMsgAsync(int, CancellationToken)

public ValueTask ExpectNoMsgAsync(int milliseconds, CancellationToken cancellationToken = default)

Parameters

milliseconds int
cancellationToken CancellationToken

Returns

ValueTask

ExpectNoMsgAsync(CancellationToken)

public ValueTask ExpectNoMsgAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask

ExpectNoMsgAsync(TimeSpan, CancellationToken)

public ValueTask ExpectNoMsgAsync(TimeSpan duration, CancellationToken cancellationToken = default)

Parameters

duration TimeSpan
cancellationToken CancellationToken

Returns

ValueTask

ExpectTerminated(IActorRef, TimeSpan?, string, CancellationToken)

Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef.

Wait time is bounded by the given duration, if specified; otherwise wait time is bounded by remaining time for execution of the innermost enclosing 'within' block, if inside a 'within' block; otherwise by the config value "akka.test.single-expect-default".

public Terminated ExpectTerminated(IActorRef target, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

target IActorRef

TBD

timeout TimeSpan?

TBD

hint string

TBD

cancellationToken CancellationToken

Returns

Terminated

TBD

ExpectTerminatedAsync(IActorRef, TimeSpan?, string, CancellationToken)

public ValueTask<Terminated> ExpectTerminatedAsync(IActorRef target, TimeSpan? timeout = null, string hint = null, CancellationToken cancellationToken = default)

Parameters

target IActorRef
timeout TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<Terminated>

FishForMessage(Predicate<object>, TimeSpan?, string, CancellationToken)

Receives messages until isMessage returns true. Use it to ignore certain messages while waiting for a specific message.

public object FishForMessage(Predicate<object> isMessage, TimeSpan? max = null, string hint = "", CancellationToken cancellationToken = default)

Parameters

isMessage Predicate<object>

The is message.

max TimeSpan?

The maximum.

hint string

The hint.

cancellationToken CancellationToken

Returns

object

Returns the message that isMessage matched

FishForMessageAsync(Predicate<object>, TimeSpan?, string, CancellationToken)

public ValueTask<object> FishForMessageAsync(Predicate<object> isMessage, TimeSpan? max = null, string hint = "", CancellationToken cancellationToken = default)

Parameters

isMessage Predicate<object>
max TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<object>

FishForMessageAsync<T>(Predicate<T>, ArrayList, TimeSpan?, string, CancellationToken)

public ValueTask<T> FishForMessageAsync<T>(Predicate<T> isMessage, ArrayList allMessages, TimeSpan? max = null, string hint = "", CancellationToken cancellationToken = default)

Parameters

isMessage Predicate<T>
allMessages ArrayList
max TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

FishForMessageAsync<T>(Predicate<T>, TimeSpan?, string, CancellationToken)

public ValueTask<T> FishForMessageAsync<T>(Predicate<T> isMessage, TimeSpan? max = null, string hint = "", CancellationToken cancellationToken = default)

Parameters

isMessage Predicate<T>
max TimeSpan?
hint string
cancellationToken CancellationToken

Returns

ValueTask<T>

Type Parameters

T

FishForMessage<T>(Predicate<T>, ArrayList, TimeSpan?, string, CancellationToken)

Receives messages until isMessage returns true. Use it to ignore certain messages while waiting for a specific message.

public T FishForMessage<T>(Predicate<T> isMessage, ArrayList allMessages, TimeSpan? max = null, string hint = "", CancellationToken cancellationToken = default)

Parameters

isMessage Predicate<T>

The is message.

allMessages ArrayList

If null then will be ignored. If not null then will be initially cleared, then filled with all the messages until isMessage returns true

max TimeSpan?

The maximum.

hint string

The hint.

cancellationToken CancellationToken

Returns

T

Returns the message that isMessage matched

Type Parameters

T

The type of the expected message. Messages of other types are ignored.

FishForMessage<T>(Predicate<T>, TimeSpan?, string, CancellationToken)

Receives messages until isMessage returns true. Use it to ignore certain messages while waiting for a specific message.

public T FishForMessage<T>(Predicate<T> isMessage, TimeSpan? max = null, string hint = "", CancellationToken cancellationToken = default)

Parameters

isMessage Predicate<T>

The is message.

max TimeSpan?

The maximum.

hint string

The hint.

cancellationToken CancellationToken

Returns

T

Returns the message that isMessage matched

Type Parameters

T

The type of the expected message. Messages of other types are ignored.

FishUntilMessageAsync<T>(TimeSpan?, CancellationToken)

Receives messages until max.

Ignores all messages except for a message of type T. Asserts that all messages are not of the of type T.

public Task FishUntilMessageAsync<T>(TimeSpan? max = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?

Optional. The maximum wait duration. Defaults to RemainingOrDefault when unset.

cancellationToken CancellationToken

Returns

Task

Type Parameters

T

The type that the message is not supposed to be.

GetTimeoutOrDefault(TimeSpan?)

If timeout is defined it is returned; otherwise the config value "akka.test.single-expect-default" is returned.

public TimeSpan GetTimeoutOrDefault(TimeSpan? timeout)

Parameters

timeout TimeSpan?

TBD

Returns

TimeSpan

TBD

IgnoreMessages(Func<object, bool>)

Ignore all messages in the test actor for which the given function returns true.

public void IgnoreMessages(Func<object, bool> shouldIgnoreMessage)

Parameters

shouldIgnoreMessage Func<object, bool>

Given a message, if the function returns true the message will be ignored by TestActor.

IgnoreMessages<TMsg>()

Ignore all messages in the test actor of the given TMsg type.

public void IgnoreMessages<TMsg>()

Type Parameters

TMsg

The type of the message to ignore.

IgnoreMessages<TMsg>(Func<TMsg, bool>)

Ignore all messages in the test actor of the given TMsg type for which the given function returns true.

public void IgnoreMessages<TMsg>(Func<TMsg, bool> shouldIgnoreMessage)

Parameters

shouldIgnoreMessage Func<TMsg, bool>

Given a message, if the function returns true the message will be ignored by TestActor.

Type Parameters

TMsg

The type of the message to ignore.

IgnoreNoMessages()

Stop ignoring messages in the test actor.

public void IgnoreNoMessages()

InitializeTest(ActorSystem, ActorSystemSetup, string, string)

Initializes the TestKitBase.TestState for a new spec.

protected virtual void InitializeTest(ActorSystem system, ActorSystemSetup config, string actorSystemName, string testActorName)

Parameters

system ActorSystem

The actor system this test will use. Can be null.

config ActorSystemSetup

The configuration that system will use if it's null.

actorSystemName string

The name that system will use if it's null.

testActorName string

The name of the test actor. Can be null.

InitializeTest(ActorSystem, Config, string, string)

Initializes the TestKitBase.TestState for a new spec.

protected void InitializeTest(ActorSystem system, Config config, string actorSystemName, string testActorName)

Parameters

system ActorSystem

The actor system this test will use. Can be null.

config Config

The configuration that system will use if it's null.

actorSystemName string

The name that system will use if it's null.

testActorName string

The name of the test actor. Can be null.

InternalAwaitCondition(Func<bool>, TimeSpan, TimeSpan?, Action<string, object[]>, ILoggingAdapter, CancellationToken)

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing `within` block.

Note that the timeout is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor".

The parameter interval specifies the time between calls to conditionIsFulfilled Between calls the thread sleeps. If interval is undefined the thread only sleeps one time, using the max as duration, and then rechecks the condition and ultimately succeeds or fails.

To make sure that tests run as fast as possible, make sure you do not leave this value as undefined, instead set it to a relatively small value.

protected static bool InternalAwaitCondition(Func<bool> conditionIsFulfilled, TimeSpan max, TimeSpan? interval, Action<string, object[]> fail, ILoggingAdapter logger, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>

The condition that must be fulfilled within the duration.

max TimeSpan

The maximum duration. The value is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor".

interval TimeSpan?

The time between calls to conditionIsFulfilled to check if the condition is fulfilled. Between calls the thread sleeps. If undefined the thread only sleeps one time, using the max, and then rechecks the condition and ultimately succeeds or fails.

To make sure that tests run as fast as possible, make sure you do not set this value as undefined, instead set it to a relatively small value.

fail Action<string, object[]>

Action that is called when the timeout expired. The parameters conforms to Format(string, params object[])

logger ILoggingAdapter

If a Akka.Event.ILoggingAdapter is specified, debug messages will be logged using it. If null nothing will be logged

cancellationToken CancellationToken

Returns

bool

TBD

InternalAwaitCondition(Func<bool>, TimeSpan, TimeSpan?, Action<string, object[]>, CancellationToken)

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing `within` block.

Note that the timeout is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor".

The parameter interval specifies the time between calls to conditionIsFulfilled Between calls the thread sleeps. If interval is undefined the thread only sleeps one time, using the max as duration, and then rechecks the condition and ultimately succeeds or fails.

To make sure that tests run as fast as possible, make sure you do not leave this value as undefined, instead set it to a relatively small value.

protected static bool InternalAwaitCondition(Func<bool> conditionIsFulfilled, TimeSpan max, TimeSpan? interval, Action<string, object[]> fail, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<bool>

The condition that must be fulfilled within the duration.

max TimeSpan

The maximum duration. The value is dilated, i.e. scaled by the factor specified in config value "akka.test.timefactor".

interval TimeSpan?

The time between calls to conditionIsFulfilled to check if the condition is fulfilled. Between calls the thread sleeps. If undefined the thread only sleeps one time, using the max, and then rechecks the condition and ultimately succeeds or fails.

To make sure that tests run as fast as possible, make sure you do not set this value as undefined, instead set it to a relatively small value.

fail Action<string, object[]>

Action that is called when the timeout expired. The parameters conforms to Format(string, params object[])

cancellationToken CancellationToken

Returns

bool

TBD

InternalAwaitConditionAsync(Func<Task<bool>>, TimeSpan, TimeSpan?, Action<string, object[]>, ILoggingAdapter, CancellationToken)

protected static Task<bool> InternalAwaitConditionAsync(Func<Task<bool>> conditionIsFulfilled, TimeSpan max, TimeSpan? interval, Action<string, object[]> fail, ILoggingAdapter logger, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<Task<bool>>
max TimeSpan
interval TimeSpan?
fail Action<string, object[]>
logger ILoggingAdapter
cancellationToken CancellationToken

Returns

Task<bool>

InternalAwaitConditionAsync(Func<Task<bool>>, TimeSpan, TimeSpan?, Action<string, object[]>, CancellationToken)

protected static Task<bool> InternalAwaitConditionAsync(Func<Task<bool>> conditionIsFulfilled, TimeSpan max, TimeSpan? interval, Action<string, object[]> fail, CancellationToken cancellationToken = default)

Parameters

conditionIsFulfilled Func<Task<bool>>
max TimeSpan
interval TimeSpan?
fail Action<string, object[]>
cancellationToken CancellationToken

Returns

Task<bool>

PeekOne(TimeSpan?, CancellationToken)

Peek one message from the head of the internal queue of the TestActor. This method blocks the specified duration or until a message is received. If no message was received, null is returned. This method does NOT automatically scale its Duration parameter using Dilated(TimeSpan)!

public object PeekOne(TimeSpan? max = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?

The maximum duration to wait. If null the config value "akka.test.single-expect-default" is used as timeout. If set to a negative value or InfiniteTimeSpan, blocks forever. This method does NOT automatically scale its Duration parameter using Dilated(TimeSpan)!

cancellationToken CancellationToken

Returns

object

The message if one was received; null otherwise

PeekOne(CancellationToken)

Peek one message from the head of the internal queue of the TestActor. This method blocks until cancelled.

public object PeekOne(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A token used to cancel the operation

Returns

object

The message if one was received; null otherwise

PeekOneAsync(TimeSpan?, CancellationToken)

public ValueTask<object> PeekOneAsync(TimeSpan? max = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?
cancellationToken CancellationToken

Returns

ValueTask<object>

PeekOneAsync(CancellationToken)

public ValueTask<object> PeekOneAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<object>

ReceiveN(int, CancellationToken)

Receive the specified number of messages using RemainingOrDefault as timeout.

public IReadOnlyCollection<object> ReceiveN(int numberOfMessages, CancellationToken cancellationToken = default)

Parameters

numberOfMessages int

The number of messages.

cancellationToken CancellationToken

Returns

IReadOnlyCollection<object>

The received messages

ReceiveN(int, TimeSpan, CancellationToken)

Receive the specified number of messages in a row before the given deadline. The deadline is scaled by "akka.test.timefactor" using Dilated(TimeSpan).

public IReadOnlyCollection<object> ReceiveN(int numberOfMessages, TimeSpan max, CancellationToken cancellationToken = default)

Parameters

numberOfMessages int

The number of messages.

max TimeSpan

The timeout scaled by "akka.test.timefactor" using Dilated(TimeSpan).

cancellationToken CancellationToken

Returns

IReadOnlyCollection<object>

The received messages

ReceiveNAsync(int, CancellationToken)

public IAsyncEnumerable<object> ReceiveNAsync(int numberOfMessages, CancellationToken cancellationToken = default)

Parameters

numberOfMessages int
cancellationToken CancellationToken

Returns

IAsyncEnumerable<object>

ReceiveNAsync(int, TimeSpan, CancellationToken)

public IAsyncEnumerable<object> ReceiveNAsync(int numberOfMessages, TimeSpan max, CancellationToken cancellationToken = default)

Parameters

numberOfMessages int
max TimeSpan
cancellationToken CancellationToken

Returns

IAsyncEnumerable<object>

ReceiveOne(TimeSpan?, CancellationToken)

Receive one message from the internal queue of the TestActor. This method blocks the specified duration or until a message is received. If no message was received, null is returned. This method does NOT automatically scale its Duration parameter using Dilated(TimeSpan)!

public object ReceiveOne(TimeSpan? max = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?

The maximum duration to wait. If null the config value "akka.test.single-expect-default" is used as timeout. If set to a negative value or InfiniteTimeSpan, blocks forever. This method does NOT automatically scale its Duration parameter using Dilated(TimeSpan)!

cancellationToken CancellationToken

Returns

object

The message if one was received; null otherwise

ReceiveOneAsync(TimeSpan?, CancellationToken)

public ValueTask<object> ReceiveOneAsync(TimeSpan? max = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?
cancellationToken CancellationToken

Returns

ValueTask<object>

ReceiveWhileAsync<T>(Func<object, T>, TimeSpan?, TimeSpan?, int, CancellationToken)

public IAsyncEnumerable<T> ReceiveWhileAsync<T>(Func<object, T> filter, TimeSpan? max = null, TimeSpan? idle = null, int msgs = 2147483647, CancellationToken cancellationToken = default)

Parameters

filter Func<object, T>
max TimeSpan?
idle TimeSpan?
msgs int
cancellationToken CancellationToken

Returns

IAsyncEnumerable<T>

Type Parameters

T

ReceiveWhileAsync<T>(TimeSpan?, Func<object, T>, int, CancellationToken)

public IAsyncEnumerable<T> ReceiveWhileAsync<T>(TimeSpan? max, Func<object, T> filter, int msgs = 2147483647, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?
filter Func<object, T>
msgs int
cancellationToken CancellationToken

Returns

IAsyncEnumerable<T>

Type Parameters

T

ReceiveWhileAsync<T>(TimeSpan?, TimeSpan?, Func<object, T>, int, CancellationToken)

public IAsyncEnumerable<T> ReceiveWhileAsync<T>(TimeSpan? max, TimeSpan? idle, Func<object, T> filter, int msgs = 2147483647, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?
idle TimeSpan?
filter Func<object, T>
msgs int
cancellationToken CancellationToken

Returns

IAsyncEnumerable<T>

Type Parameters

T

ReceiveWhileAsync<T>(Predicate<T>, TimeSpan?, TimeSpan?, int, bool, CancellationToken)

public IAsyncEnumerable<T> ReceiveWhileAsync<T>(Predicate<T> shouldContinue, TimeSpan? max = null, TimeSpan? idle = null, int msgs = 2147483647, bool shouldIgnoreOtherMessageTypes = true, CancellationToken cancellationToken = default)

Parameters

shouldContinue Predicate<T>
max TimeSpan?
idle TimeSpan?
msgs int
shouldIgnoreOtherMessageTypes bool
cancellationToken CancellationToken

Returns

IAsyncEnumerable<T>

Type Parameters

T

ReceiveWhile<T>(Func<object, T>, TimeSpan?, TimeSpan?, int, CancellationToken)

Receive a series of messages until the function returns null or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed or expected messages count is reached. Returns the sequence of messages.

Note that it is not an error to hit the max duration in this case. The max duration is scaled by Dilated(TimeSpan)

public IReadOnlyList<T> ReceiveWhile<T>(Func<object, T> filter, TimeSpan? max = null, TimeSpan? idle = null, int msgs = 2147483647, CancellationToken cancellationToken = default)

Parameters

filter Func<object, T>

TBD

max TimeSpan?

TBD

idle TimeSpan?

TBD

msgs int

TBD

cancellationToken CancellationToken

Returns

IReadOnlyList<T>

TBD

Type Parameters

T

TBD

ReceiveWhile<T>(TimeSpan?, Func<object, T>, int, CancellationToken)

Receive a series of messages until the function returns null or the overall maximum duration is elapsed or expected messages count is reached. Returns the sequence of messages.

Note that it is not an error to hit the max duration in this case. The max duration is scaled by Dilated(TimeSpan)

public IReadOnlyList<T> ReceiveWhile<T>(TimeSpan? max, Func<object, T> filter, int msgs = 2147483647, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?

TBD

filter Func<object, T>

TBD

msgs int

TBD

cancellationToken CancellationToken

Returns

IReadOnlyList<T>

TBD

Type Parameters

T

TBD

ReceiveWhile<T>(TimeSpan?, TimeSpan?, Func<object, T>, int, CancellationToken)

Receive a series of messages until the function returns null or the idle timeout is met or the overall maximum duration is elapsed or expected messages count is reached. Returns the sequence of messages.

Note that it is not an error to hit the max duration in this case. The max duration is scaled by Dilated(TimeSpan)

public IReadOnlyList<T> ReceiveWhile<T>(TimeSpan? max, TimeSpan? idle, Func<object, T> filter, int msgs = 2147483647, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?

TBD

idle TimeSpan?

TBD

filter Func<object, T>

TBD

msgs int

TBD

cancellationToken CancellationToken

Returns

IReadOnlyList<T>

TBD

Type Parameters

T

TBD

ReceiveWhile<T>(Predicate<T>, TimeSpan?, TimeSpan?, int, bool, CancellationToken)

Receive a series of messages. It will continue to receive messages until the shouldContinue predicate returns false or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed or expected messages count is reached. If a message that isn't of type T the parameter shouldIgnoreOtherMessageTypes declares if the message should be ignored or not.

Returns the sequence of messages.

Note that it is not an error to hit the max duration in this case. The max duration is scaled by Dilated(TimeSpan)

public IReadOnlyList<T> ReceiveWhile<T>(Predicate<T> shouldContinue, TimeSpan? max = null, TimeSpan? idle = null, int msgs = 2147483647, bool shouldIgnoreOtherMessageTypes = true, CancellationToken cancellationToken = default)

Parameters

shouldContinue Predicate<T>

TBD

max TimeSpan?

TBD

idle TimeSpan?

TBD

msgs int

TBD

shouldIgnoreOtherMessageTypes bool

TBD

cancellationToken CancellationToken

Returns

IReadOnlyList<T>

TBD

Type Parameters

T

TBD

RemainingOr(TimeSpan)

If inside a within block obtain time remaining for execution of the innermost enclosing within block; otherwise returns the given duration.

protected TimeSpan RemainingOr(TimeSpan duration)

Parameters

duration TimeSpan

TBD

Returns

TimeSpan

TBD

Exceptions

ArgumentException

TBD

RemainingOrDilated(TimeSpan?)

If duration is finite it is returned after it has been scaled using Dilated(TimeSpan). If duration is undefined, it returns the remaining time (if within a within block) or the properly dilated default from settings (key "akka.test.single-expect-default"). If duration is infinite, an ArgumentException is thrown. The returned value is always finite.

public TimeSpan RemainingOrDilated(TimeSpan? duration)

Parameters

duration TimeSpan?

The maximum.

Returns

TimeSpan

A finite TimeSpan properly dilated

Exceptions

ArgumentException

Thrown if duration is infinite

SetAutoPilot(AutoPilot)

Install an AutoPilot to drive the TestActor. The AutoPilot will be run for each received message and can be used to send or forward messages, etc.

Each invocation must return the AutoPilot for the next round. To reuse the same AutoPilot return KeepRunning.

public void SetAutoPilot(AutoPilot pilot)

Parameters

pilot AutoPilot

The pilot to install.

Shutdown(ActorSystem, TimeSpan?, bool)

Shuts down the specified system. On failure debug output will be logged about the remaining actors in the system. If verifySystemShutdown is true, then an exception will be thrown on failure.

protected virtual void Shutdown(ActorSystem system, TimeSpan? duration = null, bool verifySystemShutdown = false)

Parameters

system ActorSystem

The system to shutdown.

duration TimeSpan?

The duration to wait for shutdown. Default is 5 seconds multiplied with the config value "akka.test.timefactor"

verifySystemShutdown bool

if set to true an exception will be thrown on failure.

Exceptions

TimeoutException

TBD

Shutdown(TimeSpan?, bool)

Shuts down this system. On failure debug output will be logged about the remaining actors in the system. If verifySystemShutdown is true, then an exception will be thrown on failure.

public virtual void Shutdown(TimeSpan? duration = null, bool verifySystemShutdown = false)

Parameters

duration TimeSpan?

Optional. The duration to wait for shutdown. Default is 5 seconds multiplied with the config value "akka.test.timefactor".

verifySystemShutdown bool

if set to true an exception will be thrown on failure.

Exceptions

TimeoutException

TBD

TryPeekOne(out MessageEnvelope, TimeSpan?, CancellationToken)

Peek one message from the head of the internal queue of the TestActor within the specified duration.

True is returned if a message existed, and the message is returned in envelope. The method blocks the specified duration, and can be cancelled using the cancellationToken.

This method does NOT automatically scale its duration parameter using Dilated(TimeSpan)!
public bool TryPeekOne(out MessageEnvelope envelope, TimeSpan? max, CancellationToken cancellationToken)

Parameters

envelope MessageEnvelope

The received envelope.

max TimeSpan?

The maximum duration to wait. If null the config value "akka.test.single-expect-default" is used as timeout. If set to InfiniteTimeSpan, blocks forever (or until cancelled). This method does NOT automatically scale its Duration parameter using Dilated(TimeSpan)!

cancellationToken CancellationToken

A token used to cancel the operation.

Returns

bool

True if a message was received within the specified duration; false otherwise.

TryPeekOneAsync(TimeSpan?, CancellationToken)

public ValueTask<(bool success, MessageEnvelope envelope)> TryPeekOneAsync(TimeSpan? max, CancellationToken cancellationToken)

Parameters

max TimeSpan?
cancellationToken CancellationToken

Returns

ValueTask<(bool success, MessageEnvelope envelope)>

TryReceiveOne(out MessageEnvelope, TimeSpan?, CancellationToken)

Receive one message from the internal queue of the TestActor within the specified duration. The method blocks the specified duration. Note! that the returned envelope is a MessageEnvelope containing the sender and the message. This method does NOT automatically scale its Duration parameter using Dilated(TimeSpan)!

public bool TryReceiveOne(out MessageEnvelope envelope, TimeSpan? max = null, CancellationToken cancellationToken = default)

Parameters

envelope MessageEnvelope

The received envelope.

max TimeSpan?

Optional: The maximum duration to wait. If null the config value "akka.test.single-expect-default" is used as timeout. If set to a negative value or InfiniteTimeSpan, blocks forever. This method does NOT automatically scale its Duration parameter using Dilated(TimeSpan)!

cancellationToken CancellationToken

Returns

bool

True if a message was received within the specified duration; false otherwise.

TryReceiveOneAsync(TimeSpan?, CancellationToken)

public ValueTask<(bool success, MessageEnvelope envelope)> TryReceiveOneAsync(TimeSpan? max, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?
cancellationToken CancellationToken

Returns

ValueTask<(bool success, MessageEnvelope envelope)>

Unwatch(IActorRef)

Have the TestActor stop watching an actor.

public IActorRef Unwatch(IActorRef actorToUnwatch)

Parameters

actorToUnwatch IActorRef

The actor to unwatch.

Returns

IActorRef

The actor to unwatch, i.e. the parameter actorToUnwatch

UnwatchAsync(IActorRef)

Have the TestActor stop watching an actor.

public Task<IActorRef> UnwatchAsync(IActorRef actorToUnwatch)

Parameters

actorToUnwatch IActorRef

The actor to unwatch.

Returns

Task<IActorRef>

The actor to unwatch, i.e. the parameter actorToUnwatch

Remarks

This method exists in order to make the asynchronous nature of the Unwatch method explicit.

WaitForRadioSilenceAsync(TimeSpan?, uint?, CancellationToken)

Waits for a max period of 'radio-silence' limited to a number of maxMessages. Note: 'radio-silence' definition: period when no messages arrive at.

public Task<ArrayList> WaitForRadioSilenceAsync(TimeSpan? max = null, uint? maxMessages = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan?

A temporary period of 'radio-silence'.

maxMessages uint?

The method asserts that maxMessages is never reached.

cancellationToken CancellationToken

Returns

Task<ArrayList>

Returns all the messages encountered before 'radio-silence' was reached.

Watch(IActorRef)

Have the TestActor watch an actor and receive Akka.Actor.Terminated messages when the actor terminates.

public IActorRef Watch(IActorRef actorToWatch)

Parameters

actorToWatch IActorRef

The actor to watch.

Returns

IActorRef

The actor to watch, i.e. the parameter actorToWatch

WatchAsync(IActorRef)

Have the TestActor watch an actor and receive Akka.Actor.Terminated messages when the actor terminates.

public Task<IActorRef> WatchAsync(IActorRef actorToWatch)

Parameters

actorToWatch IActorRef

The actor to watch.

Returns

Task<IActorRef>

The actor to watch, i.e. the parameter actorToWatch

Remarks

This method exists in order to make the asynchronous nature of the Watch method explicit.

Within(TimeSpan, Action, TimeSpan?, CancellationToken)

Execute code block while bounding its execution time between 0 seconds and max.

`within` blocks may be nested. All methods in this class which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing `within` block.

Note that the max duration is scaled using Dilated(TimeSpan) which uses the config value "akka.test.timefactor"
public void Within(TimeSpan max, Action action, TimeSpan? epsilonValue = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan

TBD

action Action

TBD

epsilonValue TimeSpan?

TBD

cancellationToken CancellationToken

Within(TimeSpan, TimeSpan, Action, string, TimeSpan?, CancellationToken)

Execute code block while bounding its execution time between min and max.

`within` blocks may be nested. All methods in this class which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing `within` block.

Note that the max duration is scaled using Dilated(TimeSpan) which uses the config value "akka.test.timefactor"
public void Within(TimeSpan min, TimeSpan max, Action action, string hint = null, TimeSpan? epsilonValue = null, CancellationToken cancellationToken = default)

Parameters

min TimeSpan

TBD

max TimeSpan

TBD

action Action

TBD

hint string

TBD

epsilonValue TimeSpan?

TBD

cancellationToken CancellationToken

WithinAsync(TimeSpan, Func<Task>, TimeSpan?, CancellationToken)

public Task WithinAsync(TimeSpan max, Func<Task> actionAsync, TimeSpan? epsilonValue = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan
actionAsync Func<Task>
epsilonValue TimeSpan?
cancellationToken CancellationToken

Returns

Task

WithinAsync(TimeSpan, TimeSpan, Func<Task>, string, TimeSpan?, CancellationToken)

public Task WithinAsync(TimeSpan min, TimeSpan max, Func<Task> actionAsync, string hint = null, TimeSpan? epsilonValue = null, CancellationToken cancellationToken = default)

Parameters

min TimeSpan
max TimeSpan
actionAsync Func<Task>
hint string
epsilonValue TimeSpan?
cancellationToken CancellationToken

Returns

Task

WithinAsync<T>(TimeSpan, Func<Task<T>>, TimeSpan?, CancellationToken)

Execute code block while bounding its execution time between 0 seconds and max.

`within` blocks may be nested. All methods in this class which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing `within` block.

Note that the max duration is scaled using Dilated(TimeSpan) which uses the config value "akka.test.timefactor"
public Task<T> WithinAsync<T>(TimeSpan max, Func<Task<T>> function, TimeSpan? epsilonValue = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan

TBD

function Func<Task<T>>

TBD

epsilonValue TimeSpan?

TBD

cancellationToken CancellationToken

Returns

Task<T>

TBD

Type Parameters

T

TBD

WithinAsync<T>(TimeSpan, TimeSpan, Func<Task<T>>, string, TimeSpan?, CancellationToken)

Execute code block while bounding its execution time between min and max.

`within` blocks may be nested. All methods in this class which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing `within` block.

Note that the max duration is scaled using Dilated(TimeSpan) which uses the config value "akka.test.timefactor".

Note that due to how asynchronous Task is executed in managed code, there is no way to stop a running Task. If this assertion fails in any way, the function Task might still be running in the background and might not be stopped/disposed until the unit test is over.

public Task<T> WithinAsync<T>(TimeSpan min, TimeSpan max, Func<Task<T>> function, string hint = null, TimeSpan? epsilonValue = null, CancellationToken cancellationToken = default)

Parameters

min TimeSpan

TBD

max TimeSpan

TBD

function Func<Task<T>>

TBD

hint string

TBD

epsilonValue TimeSpan?

TBD

cancellationToken CancellationToken

Returns

Task<T>

TBD

Type Parameters

T

TBD

Within<T>(TimeSpan, Func<T>, TimeSpan?, CancellationToken)

Execute code block while bounding its execution time between 0 seconds and max.

`within` blocks may be nested. All methods in this class which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing `within` block.

Note that the max duration is scaled using Dilated(TimeSpan) which uses the config value "akka.test.timefactor"
public T Within<T>(TimeSpan max, Func<T> function, TimeSpan? epsilonValue = null, CancellationToken cancellationToken = default)

Parameters

max TimeSpan

TBD

function Func<T>

TBD

epsilonValue TimeSpan?

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD

Within<T>(TimeSpan, TimeSpan, Func<T>, string, TimeSpan?, CancellationToken)

Execute code block while bounding its execution time between min and max.

`within` blocks may be nested. All methods in this class which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing `within` block.

Note that the max duration is scaled using Dilated(TimeSpan) which uses the config value "akka.test.timefactor"
public T Within<T>(TimeSpan min, TimeSpan max, Func<T> function, string hint = null, TimeSpan? epsilonValue = null, CancellationToken cancellationToken = default)

Parameters

min TimeSpan

TBD

max TimeSpan

TBD

function Func<T>

TBD

hint string

TBD

epsilonValue TimeSpan?

TBD

cancellationToken CancellationToken

Returns

T

TBD

Type Parameters

T

TBD