Skip to content

Commit

Permalink
fixed context.GetPID methd for names without tags. (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
mczechyra authored Mar 4, 2023
1 parent 99e1c67 commit 21b6c41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion actor/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func (c *Context) Forward(pid *PID) {
// GetPID returns the PID of the process found by the given name and tags.
// Returns nil when it could not find any process..
func (c *Context) GetPID(name string, tags ...string) *PID {
name = name + pidSeparator + strings.Join(tags, pidSeparator)
if len(tags) > 0 {
name = name + pidSeparator + strings.Join(tags, pidSeparator)
}
proc := c.engine.Registry.getByID(name)
if proc != nil {
return proc.PID()
Expand Down
19 changes: 19 additions & 0 deletions actor/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,22 @@ func TestGetByName(t *testing.T) {

pidSeparator = restorepidSeparator
}

func TestGetByNameFromContext(t *testing.T) {
const PidName = "ReceiverFunc"

e := NewEngine()

// Receiver staless actor with given name:
e.SpawnFunc(func(c *Context) {}, PidName)
time.Sleep(10 * time.Millisecond)

// Transmitter stateless actor which want to lookup receiver by his name:
e.SpawnFunc(func(c *Context) {
pid := c.GetPID(PidName)
require.NotNil(t, pid)

expectedPID := NewPID(LocalLookupAddr, PidName)
require.Equal(t, expectedPID.String(), pid.String())
}, "TransmitterFunc")
}

0 comments on commit 21b6c41

Please sign in to comment.