Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/Proto.TestKit/ITestProbe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,34 @@ public interface ITestProbe
/// <returns></returns>
T GetNextMessage<T>(Func<T, bool> when, TimeSpan? timeAllowed = null);

/// <summary>
/// asynchronously gets the next message from the test probe
/// </summary>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<object?> GetNextMessageAsync(TimeSpan? timeAllowed = null, CancellationToken cancellationToken = default);

/// <summary>
/// asynchronously gets the next message from the test probe
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> GetNextMessageAsync<T>(TimeSpan? timeAllowed = null, CancellationToken cancellationToken = default);

/// <summary>
/// asynchronously gets the next message from the test probe
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> GetNextMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);

/// <summary>
/// keeps returning messages until the interval between messages exceeds the time allowed
/// </summary>
Expand All @@ -81,6 +109,36 @@ public interface ITestProbe
/// <returns></returns>
IEnumerable<T> ProcessMessages<T>(Func<T, bool> when, TimeSpan? timeAllowed = null);

/// <summary>
/// asynchronously processes messages until the interval between messages exceeds the time allowed
/// </summary>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
IAsyncEnumerable<object?> ProcessMessagesAsync(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);

/// <summary>
/// asynchronously processes messages until the interval between messages exceeds the time allowed
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
IAsyncEnumerable<T> ProcessMessagesAsync<T>(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);

/// <summary>
/// asynchronously processes messages until the interval between messages exceeds the time allowed
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
IAsyncEnumerable<T> ProcessMessagesAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);

/// <summary>
/// fishes for the next message of a given type from the test probe
/// </summary>
Expand All @@ -98,6 +156,26 @@ public interface ITestProbe
/// <returns></returns>
T FishForMessage<T>(Func<T, bool> when, TimeSpan? timeAllowed = null);

/// <summary>
/// asynchronously fishes for the next message of a given type from the test probe
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> FishForMessageAsync<T>(TimeSpan? timeAllowed = null, CancellationToken cancellationToken = default);

/// <summary>
/// asynchronously fishes for the next message of a given type from the test probe
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="when"></param>
/// <param name="timeAllowed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<T> FishForMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default);

/// <summary>
/// sends a message from the test probe to the target
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions src/Proto.TestKit/TestKitBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ public PID SpawnNamed(Props props, string name, Action<IContext>? callback = nul
public T GetNextMessage<T>(Func<T, bool> when, TimeSpan? timeAllowed = null) =>
Probe.GetNextMessage(when, timeAllowed);

/// <inheritdoc />
public Task<object?> GetNextMessageAsync(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) =>
Probe.GetNextMessageAsync(timeAllowed, cancellationToken);

/// <inheritdoc />
public Task<T> GetNextMessageAsync<T>(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) =>
Probe.GetNextMessageAsync<T>(timeAllowed, cancellationToken);

/// <inheritdoc />
public Task<T> GetNextMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) =>
Probe.GetNextMessageAsync(when, timeAllowed, cancellationToken);

/// <inheritdoc />
public IEnumerable ProcessMessages(TimeSpan? timeAllowed = null) => Probe.ProcessMessages(timeAllowed);

Expand All @@ -74,13 +89,38 @@ public T GetNextMessage<T>(Func<T, bool> when, TimeSpan? timeAllowed = null) =>
public IEnumerable<T> ProcessMessages<T>(Func<T, bool> when, TimeSpan? timeAllowed = null) =>
Probe.ProcessMessages(when, timeAllowed);

/// <inheritdoc />
public IAsyncEnumerable<object?> ProcessMessagesAsync(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) =>
Probe.ProcessMessagesAsync(timeAllowed, cancellationToken);

/// <inheritdoc />
public IAsyncEnumerable<T> ProcessMessagesAsync<T>(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) =>
Probe.ProcessMessagesAsync<T>(timeAllowed, cancellationToken);

/// <inheritdoc />
public IAsyncEnumerable<T> ProcessMessagesAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) =>
Probe.ProcessMessagesAsync(when, timeAllowed, cancellationToken);

/// <inheritdoc />
public T FishForMessage<T>(TimeSpan? timeAllowed = null) => Probe.FishForMessage<T>(timeAllowed);

/// <inheritdoc />
public T FishForMessage<T>(Func<T, bool> when, TimeSpan? timeAllowed = null) =>
Probe.FishForMessage(when, timeAllowed);

/// <inheritdoc />
public Task<T> FishForMessageAsync<T>(TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) =>
Probe.FishForMessageAsync<T>(timeAllowed, cancellationToken);

/// <inheritdoc />
public Task<T> FishForMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
CancellationToken cancellationToken = default) =>
Probe.FishForMessageAsync(when, timeAllowed, cancellationToken);

/// <inheritdoc />
public void Send(PID target, object message) => Probe.Send(target, message);

Expand Down
Loading
Loading