Skip to content

Commit 541ffc9

Browse files
authored
Fix ReceiveAsync resetting ReceiveTimeout (#6718)
1 parent 95000a6 commit 541ffc9

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

src/core/Akka.Tests/Actor/ReceiveTimeoutSpec.cs

+61-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
using FluentAssertions;
1717
using FluentAssertions.Extensions;
1818
using Xunit;
19+
using Xunit.Abstractions;
1920

2021

2122
namespace Akka.Tests.Actor
2223
{
24+
public class Tick { }
25+
26+
public class TransparentTick : INotInfluenceReceiveTimeout { }
27+
2328
public class ReceiveTimeoutSpec : AkkaSpec
2429
{
25-
public class Tick { }
26-
27-
public class TransparentTick : INotInfluenceReceiveTimeout { }
28-
2930
public class TimeoutActor : ActorBase
3031
{
3132
private TestLatch _timeoutLatch;
@@ -62,6 +63,38 @@ protected override bool Receive(object message)
6263
return false;
6364
}
6465
}
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+
}
6598

6699
public class TurnOffTimeoutActor : ActorBase
67100
{
@@ -120,6 +153,10 @@ protected override bool Receive(object message)
120153
}
121154
}
122155

156+
public ReceiveTimeoutSpec(ITestOutputHelper output): base(output)
157+
{
158+
}
159+
123160
[Fact]
124161
public void An_actor_with_receive_timeout_must_get_timeout()
125162
{
@@ -186,6 +223,26 @@ public void An_actor_with_receive_timeout_must_get_timeout_while_receiving_NotIn
186223
Sys.Stop(timeoutActor);
187224
}
188225

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+
189246
[Fact]
190247
public void An_actor_with_receive_timeout_must_get_timeout_while_receiving_only_NotInfluenceReceiveTimeout_messages()
191248
{

src/core/Akka/Dispatch/ActorTaskScheduler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static void RunTask(Func<Task> asyncAction)
162162
if (exception == null)
163163
{
164164
dispatcher.Resume(context);
165-
context.CheckReceiveTimeout();
165+
context.CheckReceiveTimeout(context.CurrentMessage is not INotInfluenceReceiveTimeout);
166166
}
167167
else
168168
{

0 commit comments

Comments
 (0)