File tree 2 files changed +50
-1
lines changed
Akka/Actor/Stash/Internal
2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change
1
+ // -----------------------------------------------------------------------
2
+ // <copyright file="Bugfix7398Specs.cs" company="Akka.NET Project">
3
+ // Copyright (C) 2009-2024 Lightbend Inc. <http://www.lightbend.com>
4
+ // Copyright (C) 2013-2024 .NET Foundation <https://github.com/akkadotnet/akka.net>
5
+ // </copyright>
6
+ // -----------------------------------------------------------------------
7
+
8
+ using Akka . Actor ;
9
+ using Akka . TestKit ;
10
+ using Xunit ;
11
+ using Xunit . Abstractions ;
12
+
13
+ namespace Akka . Tests . Actor . Stash ;
14
+
15
+ public class Bugfix7398Specs : AkkaSpec
16
+ {
17
+ public Bugfix7398Specs ( ITestOutputHelper output )
18
+ : base ( output )
19
+ {
20
+ }
21
+
22
+ private class IllegalStashActor : UntypedActor , IWithStash
23
+ {
24
+ protected override void OnReceive ( object message )
25
+ {
26
+
27
+ }
28
+
29
+ protected override void PreStart ( )
30
+ {
31
+ // ILLEGAL
32
+ Stash . Stash ( ) ;
33
+ }
34
+
35
+ public IStash Stash { get ; set ; }
36
+ }
37
+
38
+ [ Fact ]
39
+ public void Should_throw_exception_when_stashing_in_PreStart ( )
40
+ {
41
+ EventFilter . Exception < ActorInitializationException > ( ) . ExpectOne ( ( ) =>
42
+ {
43
+ var actor = Sys . ActorOf ( Props . Create < IllegalStashActor > ( ) ) ;
44
+ actor . Tell ( "hello" ) ;
45
+ } ) ;
46
+ }
47
+ }
Original file line number Diff line number Diff line change @@ -74,9 +74,11 @@ public void Stash()
74
74
{
75
75
var currMsg = _actorCell . CurrentMessage ;
76
76
var sender = _actorCell . Sender ;
77
-
77
+
78
78
if ( _actorCell . CurrentEnvelopeId == _currentEnvelopeId )
79
79
{
80
+ if ( currMsg is null )
81
+ throw new InvalidOperationException ( "There is no message to stash right now. Stash() must be called inside an actor's Receive methods." ) ;
80
82
throw new IllegalActorStateException ( $ "Can't stash the same message { currMsg } more than once") ;
81
83
}
82
84
_currentEnvelopeId = _actorCell . CurrentEnvelopeId ;
You can’t perform that action at this time.
0 commit comments