github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/deadletter_test.go (about) 1 package actor 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestDeadLetterAfterStop(t *testing.T) { 10 a := rootContext.Spawn(PropsFromProducer(NewBlackHoleActor)) 11 done := false 12 sub := system.EventStream.Subscribe(func(msg interface{}) { 13 if deadLetter, ok := msg.(*DeadLetterEvent); ok { 14 if deadLetter.PID == a { 15 done = true 16 } 17 } 18 }) 19 defer system.EventStream.Unsubscribe(sub) 20 21 _ = rootContext.StopFuture(a).Wait() 22 23 rootContext.Send(a, "hello") 24 25 assert.True(t, done) 26 } 27 28 func TestDeadLetterWatchRespondsWithTerminate(t *testing.T) { 29 // create an actor 30 pid := rootContext.Spawn(PropsFromProducer(NewBlackHoleActor)) 31 // stop id 32 _ = rootContext.StopFuture(pid).Wait() 33 f := NewFuture(system, testTimeout) 34 // send a watch message, from our future 35 pid.sendSystemMessage(system, &Watch{Watcher: f.PID()}) 36 assertFutureSuccess(f, t) 37 }