-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathTestProbeAsyncTests.cs
More file actions
50 lines (42 loc) · 1.26 KB
/
TestProbeAsyncTests.cs
File metadata and controls
50 lines (42 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Threading.Tasks;
using Proto;
using Proto.TestKit;
using Xunit;
namespace Proto.Tests;
public class TestProbeAsyncTests
{
[Fact]
public async Task Probe_can_await_next_message()
{
await using var system = new ActorSystem();
var (probe, probePid) = system.CreateTestProbe();
var target = system.Root.Spawn(Props.FromFunc(ctx =>
{
if (ctx.Message is string s)
{
ctx.Send(probePid, s);
}
return Task.CompletedTask;
}));
system.Root.Send(target, "hello");
await probe.GetNextMessageAsync<string>(s => s == "hello");
}
[Fact]
public async Task Probe_can_wait_for_specific_message()
{
await using var system = new ActorSystem();
var (probe, probePid) = system.CreateTestProbe();
var target = system.Root.Spawn(Props.FromFunc(ctx =>
{
if (ctx.Message is string s)
{
ctx.Send(probePid, s);
}
return Task.CompletedTask;
}));
system.Root.Send(target, "one");
system.Root.Send(target, "two");
var msg = await probe.FishForMessageAsync<string>(x => x == "two");
Assert.Equal("two", msg);
}
}