Skip to content

Commit

Permalink
add a test that deadlocks the engine. (#104)
Browse files Browse the repository at this point in the history
* add a test that deadlocks the engine.

* fix the deadlock.
  • Loading branch information
perbu authored Dec 11, 2023
1 parent 629e47e commit 877828d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions actor/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ func TestSpawn(t *testing.T) {
wg.Wait()
}

func TestSpawnDuplicateId(t *testing.T) {
e, err := NewEngine()
require.NoError(t, err)
wg := sync.WaitGroup{}
pid1 := e.Spawn(NewTestProducer(t, func(t *testing.T, ctx *Context) {}), "dummy")
e.Send(pid1, 1)
pid2 := e.Spawn(NewTestProducer(t, func(t *testing.T, ctx *Context) {}), "dummy")
e.Send(pid2, 2)
wg.Wait()
}

func TestStopWaitGroup(t *testing.T) {
var (
wg = sync.WaitGroup{}
Expand Down
4 changes: 3 additions & 1 deletion actor/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ func (r *Registry) getByID(id string) Processer {
// decide?
func (r *Registry) add(proc Processer) {
r.mu.Lock()
defer r.mu.Unlock()

id := proc.PID().ID
if _, ok := r.lookup[id]; ok {
r.mu.Unlock()
r.engine.BroadcastEvent(ActorDuplicateIdEvent{PID: proc.PID()})
return
}
r.lookup[id] = proc
r.mu.Unlock()
}

0 comments on commit 877828d

Please sign in to comment.