Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spawning actors with duplicate id bug #164

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion actor/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (e *Engine) SpawnFunc(f func(*Context), kind string, opts ...OptFunc) *PID
// with custom created Processes. Take a look at the streamWriter as an example.
func (e *Engine) SpawnProc(p Processer) *PID {
e.Registry.add(p)
p.Start()
return p.PID()
}

Expand Down
17 changes: 16 additions & 1 deletion actor/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestSpawn(t *testing.T) {
wg.Wait()
}

func TestSpawnDuplicateId(t *testing.T) {
func TestSpawnDuplicateKind(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed this existing test case to be more accurate

e, err := NewEngine(NewEngineConfig())
require.NoError(t, err)
wg := sync.WaitGroup{}
Expand All @@ -234,6 +234,21 @@ func TestSpawnDuplicateId(t *testing.T) {
wg.Wait()
}

func TestSpawnDuplicateId(t *testing.T) {
e, err := NewEngine(NewEngineConfig())
require.NoError(t, err)
var startsCount int32 = 0
receiveFunc := func(t *testing.T, ctx *Context) {
switch ctx.Message().(type) {
case Initialized:
atomic.AddInt32(&startsCount, 1)
}
}
e.Spawn(NewTestProducer(t, receiveFunc), "dummy", WithID("1"))
e.Spawn(NewTestProducer(t, receiveFunc), "dummy", WithID("1"))
assert.Equal(t, int32(1), startsCount) // should only spawn one actor
}

func TestStopWaitGroup(t *testing.T) {
var (
wg = sync.WaitGroup{}
Expand Down
1 change: 1 addition & 0 deletions actor/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ func (r *Registry) add(proc Processer) {
}
r.lookup[id] = proc
r.mu.Unlock()
proc.Start()
}
Loading