diff --git a/actor/engine.go b/actor/engine.go index ef9aa33..efe9fda 100644 --- a/actor/engine.go +++ b/actor/engine.go @@ -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() } diff --git a/actor/engine_test.go b/actor/engine_test.go index 1201300..4a08a26 100644 --- a/actor/engine_test.go +++ b/actor/engine_test.go @@ -223,7 +223,7 @@ func TestSpawn(t *testing.T) { wg.Wait() } -func TestSpawnDuplicateId(t *testing.T) { +func TestSpawnDuplicateKind(t *testing.T) { e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg := sync.WaitGroup{} @@ -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{} diff --git a/actor/registry.go b/actor/registry.go index be190ac..8f578b8 100644 --- a/actor/registry.go +++ b/actor/registry.go @@ -67,4 +67,5 @@ func (r *Registry) add(proc Processer) { } r.lookup[id] = proc r.mu.Unlock() + proc.Start() }