mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-09-26 19:41:13 +08:00

* Adds 'match' configuration * test * Adds Caddy's matcher. * Adds no-fileserver test. * Prevents duplicate path calculations and optimizes worker access. * trigger * Changes worker->match to match->worker * Adjusts tests. * formatting * Resets implementation to worker->match * Provisions match path rules. * Allows matching multiple paths * Fixes var * Formatting. * refactoring. * Adds 'match' configuration * test * Adds Caddy's matcher. * Adds no-fileserver test. * Prevents duplicate path calculations and optimizes worker access. * trigger * Changes worker->match to match->worker * Adjusts tests. * formatting * Resets implementation to worker->match * Provisions match path rules. * Allows matching multiple paths * Fixes var * Formatting. * refactoring. * Update frankenphp.go Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * Update caddy/workerconfig.go Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * Update caddy/workerconfig.go Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * Update caddy/module.go Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * Update caddy/module.go Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * Fixes suggestion * Refactoring. * Adds 'match' configuration * test * Adds Caddy's matcher. * Adds no-fileserver test. * Prevents duplicate path calculations and optimizes worker access. * trigger * Changes worker->match to match->worker * Adjusts tests. * formatting * Resets implementation to worker->match * Provisions match path rules. * Allows matching multiple paths * Fixes var * Formatting. * refactoring. * Adds docs. * Fixes merge removal. * Update config.md * go fmt. * Adds line ending to static.txt and fixes tests. * Trigger CI * fix Markdown CS --------- Co-authored-by: Alliballibaba <alliballibaba@gmail.com> Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package frankenphp
|
|
|
|
import (
|
|
"io"
|
|
"log/slog"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestScaleARegularThreadUpAndDown(t *testing.T) {
|
|
assert.NoError(t, Init(
|
|
WithNumThreads(1),
|
|
WithMaxThreads(2),
|
|
WithLogger(slog.New(slog.NewTextHandler(io.Discard, nil))),
|
|
))
|
|
|
|
autoScaledThread := phpThreads[1]
|
|
|
|
// scale up
|
|
scaleRegularThread()
|
|
assert.Equal(t, stateReady, autoScaledThread.state.get())
|
|
assert.IsType(t, ®ularThread{}, autoScaledThread.handler)
|
|
|
|
// on down-scale, the thread will be marked as inactive
|
|
setLongWaitTime(autoScaledThread)
|
|
deactivateThreads()
|
|
assert.IsType(t, &inactiveThread{}, autoScaledThread.handler)
|
|
|
|
Shutdown()
|
|
}
|
|
|
|
func TestScaleAWorkerThreadUpAndDown(t *testing.T) {
|
|
workerName := "worker1"
|
|
workerPath := testDataPath + "/transition-worker-1.php"
|
|
assert.NoError(t, Init(
|
|
WithNumThreads(2),
|
|
WithMaxThreads(3),
|
|
WithWorkers(workerName, workerPath, 1,
|
|
WithWorkerEnv(map[string]string{}),
|
|
WithWorkerWatchMode([]string{}),
|
|
WithWorkerMaxFailures(0),
|
|
),
|
|
WithLogger(slog.New(slog.NewTextHandler(io.Discard, nil))),
|
|
))
|
|
|
|
autoScaledThread := phpThreads[2]
|
|
|
|
// scale up
|
|
scaleWorkerThread(getWorkerByPath(workerPath))
|
|
assert.Equal(t, stateReady, autoScaledThread.state.get())
|
|
|
|
// on down-scale, the thread will be marked as inactive
|
|
setLongWaitTime(autoScaledThread)
|
|
deactivateThreads()
|
|
assert.IsType(t, &inactiveThread{}, autoScaledThread.handler)
|
|
|
|
Shutdown()
|
|
}
|
|
|
|
func setLongWaitTime(thread *phpThread) {
|
|
thread.state.mu.Lock()
|
|
thread.state.waitingSince = time.Now().Add(-time.Hour)
|
|
thread.state.mu.Unlock()
|
|
}
|