|
16 | 16 | using FluentAssertions;
|
17 | 17 | using FluentAssertions.Extensions;
|
18 | 18 | using Xunit;
|
| 19 | +using Xunit.Abstractions; |
19 | 20 |
|
20 | 21 |
|
21 | 22 | namespace Akka.Tests.Actor
|
22 | 23 | {
|
| 24 | + public class Tick { } |
| 25 | + |
| 26 | + public class TransparentTick : INotInfluenceReceiveTimeout { } |
| 27 | + |
23 | 28 | public class ReceiveTimeoutSpec : AkkaSpec
|
24 | 29 | {
|
25 |
| - public class Tick { } |
26 |
| - |
27 |
| - public class TransparentTick : INotInfluenceReceiveTimeout { } |
28 |
| - |
29 | 30 | public class TimeoutActor : ActorBase
|
30 | 31 | {
|
31 | 32 | private TestLatch _timeoutLatch;
|
@@ -62,6 +63,38 @@ protected override bool Receive(object message)
|
62 | 63 | return false;
|
63 | 64 | }
|
64 | 65 | }
|
| 66 | + |
| 67 | + public class AsyncTimeoutActor : ReceiveActor |
| 68 | + { |
| 69 | + public AsyncTimeoutActor(TestLatch timeoutLatch) |
| 70 | + : this(timeoutLatch, TimeSpan.FromMilliseconds(500)) |
| 71 | + { |
| 72 | + } |
| 73 | + |
| 74 | + public AsyncTimeoutActor(TestLatch timeoutLatch, TimeSpan? timeout) |
| 75 | + { |
| 76 | + var log = Context.GetLogger(); |
| 77 | + |
| 78 | + Context.SetReceiveTimeout(timeout.GetValueOrDefault()); |
| 79 | + |
| 80 | + ReceiveAsync<ReceiveTimeout>(async _ => |
| 81 | + { |
| 82 | + log.Info($"Received {nameof(ReceiveTimeout)}"); |
| 83 | + timeoutLatch.Open(); |
| 84 | + }); |
| 85 | + |
| 86 | + ReceiveAsync<TransparentTick>(async _ => |
| 87 | + { |
| 88 | + log.Info($"Received {nameof(TransparentTick)}"); |
| 89 | + }); |
| 90 | + |
| 91 | + ReceiveAsync<Tick>(async _ => |
| 92 | + { |
| 93 | + log.Info($"Received {nameof(Tick)}"); |
| 94 | + }); |
| 95 | + } |
| 96 | + |
| 97 | + } |
65 | 98 |
|
66 | 99 | public class TurnOffTimeoutActor : ActorBase
|
67 | 100 | {
|
@@ -120,6 +153,10 @@ protected override bool Receive(object message)
|
120 | 153 | }
|
121 | 154 | }
|
122 | 155 |
|
| 156 | + public ReceiveTimeoutSpec(ITestOutputHelper output): base(output) |
| 157 | + { |
| 158 | + } |
| 159 | + |
123 | 160 | [Fact]
|
124 | 161 | public void An_actor_with_receive_timeout_must_get_timeout()
|
125 | 162 | {
|
@@ -186,6 +223,26 @@ public void An_actor_with_receive_timeout_must_get_timeout_while_receiving_NotIn
|
186 | 223 | Sys.Stop(timeoutActor);
|
187 | 224 | }
|
188 | 225 |
|
| 226 | + [Fact] |
| 227 | + public void An_async_actor_with_receive_timeout_must_get_timeout_while_receiving_NotInfluenceReceiveTimeout_messages() |
| 228 | + { |
| 229 | + var timeoutLatch = new TestLatch(); |
| 230 | + var timeoutActor = Sys.ActorOf(Props.Create(() => new AsyncTimeoutActor(timeoutLatch, TimeSpan.FromSeconds(1)))); |
| 231 | + |
| 232 | + var cancelable = Sys.Scheduler.Advanced.ScheduleRepeatedlyCancelable( |
| 233 | + TimeSpan.FromMilliseconds(100), |
| 234 | + TimeSpan.FromMilliseconds(100), |
| 235 | + () => |
| 236 | + { |
| 237 | + timeoutActor.Tell(new TransparentTick()); |
| 238 | + //timeoutActor.Tell(new Identify(null)); |
| 239 | + }); |
| 240 | + |
| 241 | + timeoutLatch.Ready(TestKitSettings.DefaultTimeout); |
| 242 | + cancelable.Cancel(); |
| 243 | + Sys.Stop(timeoutActor); |
| 244 | + } |
| 245 | + |
189 | 246 | [Fact]
|
190 | 247 | public void An_actor_with_receive_timeout_must_get_timeout_while_receiving_only_NotInfluenceReceiveTimeout_messages()
|
191 | 248 | {
|
|
0 commit comments