Skip to content

Commit bc48bdd

Browse files
committed
bring error on second global worker with the same filename again
1 parent 00d819f commit bc48bdd

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

phpmainthread_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestStartAndStopTheMainThreadWithOneInactiveThread(t *testing.T) {
3232
}
3333

3434
func TestTransitionRegularThreadToWorkerThread(t *testing.T) {
35+
workers = nil
3536
logger = zap.NewNop()
3637
_, err := initPHPThreads(1, 1, nil)
3738
assert.NoError(t, err)
@@ -56,6 +57,7 @@ func TestTransitionRegularThreadToWorkerThread(t *testing.T) {
5657
}
5758

5859
func TestTransitionAThreadBetween2DifferentWorkers(t *testing.T) {
60+
workers = nil
5961
logger = zap.NewNop()
6062
_, err := initPHPThreads(1, 1, nil)
6163
assert.NoError(t, err)
@@ -156,6 +158,7 @@ func TestAllCommonHeadersAreCorrect(t *testing.T) {
156158
}
157159
}
158160
func TestFinishBootingAWorkerScript(t *testing.T) {
161+
workers = nil
159162
logger = zap.NewNop()
160163
_, err := initPHPThreads(1, 1, nil)
161164
assert.NoError(t, err)

worker.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ func newWorker(o workerOpt) (*worker, error) {
9191
// Check if a worker with the same fileName and moduleID already exists
9292
if existingWorkers, ok := workers[absFileName]; ok {
9393
for _, existingWorker := range existingWorkers {
94-
if existingWorker.moduleID == o.moduleID && o.moduleID != 0 {
94+
if existingWorker.moduleID == o.moduleID {
95+
if o.moduleID == 0 {
96+
return nil, fmt.Errorf("cannot add multiple global workers with the same filename: %s", absFileName)
97+
}
9598
return existingWorker, nil
9699
}
97100
}

0 commit comments

Comments
 (0)