github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/pid_test.go (about)

     1  package actor
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  type ShortLivingActor struct{}
    11  
    12  func (sl *ShortLivingActor) Receive(Context) {
    13  }
    14  
    15  func TestStopFuture(t *testing.T) {
    16  
    17  	ID := "UniqueID"
    18  	{
    19  		props := PropsFromProducer(func() Actor { return &ShortLivingActor{} })
    20  		a, _ := rootContext.SpawnNamed(props, ID)
    21  
    22  		fut := rootContext.StopFuture(a)
    23  
    24  		res, errR := fut.Result()
    25  		if errR != nil {
    26  			assert.Fail(t, "Failed to wait stop actor %pids", errR)
    27  			return
    28  		}
    29  
    30  		_, ok := res.(*Terminated)
    31  		if !ok {
    32  			assert.Fail(t, "Cannot cast %pids", reflect.TypeOf(res))
    33  			return
    34  		}
    35  
    36  		_, found := system.ProcessRegistry.Get(a)
    37  		assert.False(t, found)
    38  	}
    39  }