@@ -22,28 +22,28 @@ public class ActorLifeCycleSpec : AkkaSpec
22
22
{
23
23
public class LifeCycleTestActor : UntypedActor
24
24
{
25
- private AtomicCounter generationProvider ;
26
- private string id ;
27
- private IActorRef testActor ;
28
- private int CurrentGeneration ;
25
+ private AtomicCounter _generationProvider ;
26
+ private readonly string _id ;
27
+ private readonly IActorRef _testActor ;
28
+ private readonly int _currentGeneration ;
29
29
public LifeCycleTestActor ( IActorRef testActor , string id , AtomicCounter generationProvider )
30
30
{
31
- this . testActor = testActor ;
32
- this . id = id ;
33
- this . generationProvider = generationProvider ;
34
- this . CurrentGeneration = generationProvider . Next ( ) ;
31
+ _testActor = testActor ;
32
+ _id = id ;
33
+ _generationProvider = generationProvider ;
34
+ _currentGeneration = generationProvider . Next ( ) ;
35
35
}
36
36
37
37
private void Report ( object message )
38
38
{
39
- testActor . Tell ( ( ( string ) message , id , CurrentGeneration ) ) ;
39
+ _testActor . Tell ( ( ( string ) message , _id , _currentGeneration ) ) ;
40
40
}
41
41
42
42
protected override void OnReceive ( object message )
43
43
{
44
44
if ( message is string s && s == "status" )
45
45
{
46
- testActor . Tell ( ( "OK" , id , CurrentGeneration ) ) ;
46
+ _testActor . Tell ( ( "OK" , _id , _currentGeneration ) ) ;
47
47
}
48
48
}
49
49
@@ -323,16 +323,16 @@ public class Count { }
323
323
324
324
public class KillableActor : UntypedActor
325
325
{
326
- private IActorRef testActor ;
326
+ private readonly IActorRef _testActor ;
327
327
public KillableActor ( IActorRef testActor )
328
328
{
329
- this . testActor = testActor ;
329
+ _testActor = testActor ;
330
330
}
331
331
332
332
protected override void PostStop ( )
333
333
{
334
334
Debug . WriteLine ( "inside poststop" ) ;
335
- testActor . Tell ( ( "Terminated" , Self . Path . Name ) ) ;
335
+ _testActor . Tell ( ( "Terminated" , Self . Path . Name ) ) ;
336
336
}
337
337
338
338
protected override void OnReceive ( object message )
@@ -378,7 +378,7 @@ public async Task Clear_child_upon_terminated()
378
378
}
379
379
380
380
381
- class MyCustomException : Exception { }
381
+ private class MyCustomException : Exception { }
382
382
383
383
[ Fact ( DisplayName = "PreRestart should receive correct cause, message and sender" ) ]
384
384
public async Task Call_PreStart_with_correct_message_and_sender ( )
@@ -393,7 +393,12 @@ public async Task Call_PreStart_with_correct_message_and_sender()
393
393
c . OnPreRestart = ( ex , mess , context ) =>
394
394
{
395
395
TestActor . Tell ( ex ) ;
396
- TestActor . Tell ( mess ) ;
396
+
397
+ // can't relay the Restart back because that will blow up the TestActor
398
+ if ( mess is not IntentionalRestart )
399
+ {
400
+ TestActor . Tell ( mess ) ;
401
+ }
397
402
TestActor . Tell ( context . Sender ) ;
398
403
} ;
399
404
} ) ;
@@ -405,6 +410,11 @@ public async Task Call_PreStart_with_correct_message_and_sender()
405
410
await ExpectMsgAsync < MyCustomException > ( ) ;
406
411
await ExpectMsgAsync ( message ) ;
407
412
await ExpectMsgAsync ( TestActor ) ;
413
+
414
+ // test the `Restart` built-in message
415
+ broken . Tell ( IntentionalRestart . Instance ) ;
416
+ await ExpectMsgAsync < IntentionalActorRestartException > ( ) ;
417
+ await ExpectMsgAsync ( TestActor ) ;
408
418
}
409
419
}
410
420
}
0 commit comments