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

     1  package actor
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  type EsTestMsg struct{}
     8  
     9  func TestSendsMessagesToEventStream(t *testing.T) {
    10  	testCases := []struct {
    11  		name    string
    12  		message interface{}
    13  	}{
    14  		{name: "plain", message: &EsTestMsg{}},
    15  		{name: "envelope", message: WrapEnvelope(&EsTestMsg{})},
    16  	}
    17  
    18  	for _, testCase := range testCases {
    19  		t.Run(testCase.name, func(t *testing.T) {
    20  			system := NewActorSystem()
    21  
    22  			gotMessageChan := make(chan struct{}, 1)
    23  
    24  			subscription := system.EventStream.Subscribe(func(evt interface{}) {
    25  				if _, ok := evt.(*EsTestMsg); ok {
    26  					gotMessageChan <- struct{}{}
    27  				}
    28  			})
    29  			defer system.EventStream.Unsubscribe(subscription)
    30  
    31  			pid := system.NewLocalPID("eventstream")
    32  
    33  			system.Root.Send(pid, testCase.message)
    34  
    35  			<-gotMessageChan
    36  		})
    37  	}
    38  }