Skip to content

Commit

Permalink
Added async API to Akka.TestKit (#4075)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorFedchenko authored and Aaronontheweb committed Dec 3, 2019
1 parent 4a91b7c commit 6a29065
Show file tree
Hide file tree
Showing 7 changed files with 641 additions and 5 deletions.
133 changes: 132 additions & 1 deletion src/core/Akka.TestKit/EventFilter/IEventFilterApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//-----------------------------------------------------------------------

using System;
using System.Threading.Tasks;

namespace Akka.TestKit
{
Expand All @@ -24,6 +25,26 @@ public interface IEventFilterApplier
/// </summary>
/// <param name="action">The action.</param>
void ExpectOne(Action action);

/// <summary>
/// Executes <paramref name="action"/> and
/// expects one event to be logged during the execution.
/// This method fails and throws an exception if more than one event is logged,
/// or if a timeout occurs. The timeout is taken from the config value
/// "akka.test.filter-leeway", see <see cref="TestKitSettings.TestEventFilterLeeway"/>.
/// </summary>
/// <param name="action">The action.</param>
Task ExpectOneAsync(Action action);

/// <summary>
/// Executes <paramref name="actionAsync"/> and
/// expects one event to be logged during the execution.
/// This method fails and throws an exception if more than one event is logged,
/// or if a timeout occurs. The timeout is taken from the config value
/// "akka.test.filter-leeway", see <see cref="TestKitSettings.TestEventFilterLeeway"/>.
/// </summary>
/// <param name="actionAsync">The action.</param>
Task ExpectOneAsync(Func<Task> actionAsync);

/// <summary>
/// Executes <paramref name="action"/> and
Expand All @@ -34,7 +55,17 @@ public interface IEventFilterApplier
/// <param name="timeout">The time to wait for a log event after executing <paramref name="action"/></param>
/// <param name="action">The action.</param>
void ExpectOne(TimeSpan timeout, Action action);


/// <summary>
/// Executes <paramref name="action"/> and
/// expects one event to be logged during the execution.
/// This method fails and throws an exception if more than one event is logged,
/// or if a timeout occurs.
/// </summary>
/// <param name="timeout">The time to wait for a log event after executing <paramref name="action"/></param>
/// <param name="action">The action.</param>
Task ExpectOneAsync(TimeSpan timeout, Action action);

/// <summary>
/// Executes <paramref name="action"/> and expects the specified number
/// of events to be logged during the execution.
Expand All @@ -45,6 +76,28 @@ public interface IEventFilterApplier
/// <param name="expectedCount">The expected number of events</param>
/// <param name="action">The action.</param>
void Expect(int expectedCount, Action action);

/// <summary>
/// Executes <paramref name="action"/> and expects the specified number
/// of events to be logged during the execution.
/// This method fails and throws an exception if more events than expected are logged,
/// or if a timeout occurs. The timeout is taken from the config value
/// "akka.test.filter-leeway", see <see cref="TestKitSettings.TestEventFilterLeeway"/>.
/// </summary>
/// <param name="expectedCount">The expected number of events</param>
/// <param name="action">The action.</param>
Task ExpectAsync(int expectedCount, Action action);

/// <summary>
/// Executes <paramref name="actionAsync"/> task and expects the specified number
/// of events to be logged during the execution.
/// This method fails and throws an exception if more events than expected are logged,
/// or if a timeout occurs. The timeout is taken from the config value
/// "akka.test.filter-leeway", see <see cref="TestKitSettings.TestEventFilterLeeway"/>.
/// </summary>
/// <param name="expectedCount">The expected number of events</param>
/// <param name="actionAsync">The async action.</param>
Task ExpectAsync(int expectedCount, Func<Task> actionAsync);

/// <summary>
/// Executes <paramref name="action"/> and expects the specified number
Expand All @@ -57,6 +110,18 @@ public interface IEventFilterApplier
/// <param name="expectedCount">The expected number of events</param>
/// <param name="action">The action.</param>
void Expect(int expectedCount, TimeSpan timeout, Action action);

/// <summary>
/// Executes <paramref name="action"/> and expects the specified number
/// of events to be logged during the execution.
/// This method fails and throws an exception if more events than expected are logged,
/// or if a timeout occurs. The timeout is taken from the config value
/// "akka.test.filter-leeway", see <see cref="TestKitSettings.TestEventFilterLeeway"/>.
/// </summary>
/// <param name="timeout">The time to wait for log events after executing <paramref name="action"/></param>
/// <param name="expectedCount">The expected number of events</param>
/// <param name="action">The action.</param>
Task ExpectAsync(int expectedCount, TimeSpan timeout, Action action);

/// <summary>
/// Executes <paramref name="func"/> and
Expand All @@ -69,6 +134,18 @@ public interface IEventFilterApplier
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
T ExpectOne<T>(Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and
/// expects one event to be logged during the execution.
/// This function fails and throws an exception if more than one event is logged,
/// or if a timeout occurs. The timeout is taken from the config value
/// "akka.test.filter-leeway", see <see cref="TestKitSettings.TestEventFilterLeeway"/>.
/// </summary>
/// <typeparam name="T">The return value of the function</typeparam>
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
Task<T> ExpectOneAsync<T>(Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and
Expand All @@ -81,6 +158,18 @@ public interface IEventFilterApplier
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
T ExpectOne<T>(TimeSpan timeout, Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and
/// expects one event to be logged during the execution.
/// This function fails and throws an exception if more than one event is logged,
/// or if a timeout occurs.
/// </summary>
/// <typeparam name="T">The return value of the function</typeparam>
/// <param name="timeout">The time to wait for a log event after executing <paramref name="func"/></param>
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
Task<T> ExpectOneAsync<T>(TimeSpan timeout, Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and expects the specified number
Expand All @@ -94,6 +183,19 @@ public interface IEventFilterApplier
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
T Expect<T>(int expectedCount, Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and expects the specified number
/// of events to be logged during the execution.
/// This function fails and throws an exception if more events than expected are logged,
/// or if a timeout occurs. The timeout is taken from the config value
/// "akka.test.filter-leeway", see <see cref="TestKitSettings.TestEventFilterLeeway"/>.
/// </summary>
/// <typeparam name="T">The return value of the function</typeparam>
/// <param name="expectedCount">The expected number of events</param>
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
Task<T> ExpectAsync<T>(int expectedCount, Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and expects the specified number
Expand All @@ -108,6 +210,20 @@ public interface IEventFilterApplier
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
T Expect<T>(int expectedCount, TimeSpan timeout, Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and expects the specified number
/// of events to be logged during the execution.
/// This function fails and throws an exception if more events than expected are logged,
/// or if a timeout occurs. The timeout is taken from the config value
/// "akka.test.filter-leeway", see <see cref="TestKitSettings.TestEventFilterLeeway"/>.
/// </summary>
/// <typeparam name="T">The return value of the function</typeparam>
/// <param name="timeout">The time to wait for log events after executing <paramref name="func"/></param>
/// <param name="expectedCount">The expected number of events</param>
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
Task<T> ExpectAsync<T>(int expectedCount, TimeSpan timeout, Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and prevent events from being logged during the execution.
Expand All @@ -116,13 +232,28 @@ public interface IEventFilterApplier
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
T Mute<T>(Func<T> func);

/// <summary>
/// Executes <paramref name="func"/> and prevent events from being logged during the execution.
/// </summary>
/// <typeparam name="T">The return value of the function</typeparam>
/// <param name="func">The function.</param>
/// <returns>The returned value from <paramref name="func"/>.</returns>
Task<T> MuteAsync<T>(Func<T> func);

/// <summary>
/// Executes <paramref name="action"/> and prevent events from being logged during the execution.
/// </summary>
/// <param name="action">The function.</param>
/// <returns>The returned value from <paramref name="action"/>.</returns>
void Mute(Action action);

/// <summary>
/// Executes <paramref name="action"/> and prevent events from being logged during the execution.
/// </summary>
/// <param name="action">The function.</param>
/// <returns>The returned value from <paramref name="action"/>.</returns>
Task MuteAsync(Action action);

/// <summary>
/// Prevents events from being logged from now on. To allow events to be logged again, call
Expand Down
Loading

0 comments on commit 6a29065

Please sign in to comment.