mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
As discussed in https://github.com/php/frankenphp/discussions/1961, there is no real way to pass a severity/level to any log handler offered by PHP that would make it to the FrankenPHP layer. This new function allows applications embedding FrankenPHP to integrate PHP logging into the application itself, thus offering a more streamlined experience. --------- Co-authored-by: Quentin Burgess <qutn.burgess@gmail.com> Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package frankenphp
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/dunglas/frankenphp/internal/state"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestScaleARegularThreadUpAndDown(t *testing.T) {
|
|
t.Cleanup(Shutdown)
|
|
|
|
assert.NoError(t, Init(
|
|
WithNumThreads(1),
|
|
WithMaxThreads(2),
|
|
))
|
|
|
|
autoScaledThread := phpThreads[1]
|
|
|
|
// scale up
|
|
scaleRegularThread()
|
|
assert.Equal(t, state.Ready, autoScaledThread.state.Get())
|
|
assert.IsType(t, ®ularThread{}, autoScaledThread.handler)
|
|
|
|
// on down-scale, the thread will be marked as inactive
|
|
setLongWaitTime(t, autoScaledThread)
|
|
deactivateThreads()
|
|
assert.IsType(t, &inactiveThread{}, autoScaledThread.handler)
|
|
}
|
|
|
|
func TestScaleAWorkerThreadUpAndDown(t *testing.T) {
|
|
t.Cleanup(Shutdown)
|
|
|
|
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),
|
|
),
|
|
))
|
|
|
|
autoScaledThread := phpThreads[2]
|
|
|
|
// scale up
|
|
scaleWorkerThread(getWorkerByPath(workerPath))
|
|
assert.Equal(t, state.Ready, autoScaledThread.state.Get())
|
|
|
|
// on down-scale, the thread will be marked as inactive
|
|
setLongWaitTime(t, autoScaledThread)
|
|
deactivateThreads()
|
|
assert.IsType(t, &inactiveThread{}, autoScaledThread.handler)
|
|
}
|
|
|
|
func setLongWaitTime(t *testing.T, thread *phpThread) {
|
|
t.Helper()
|
|
|
|
thread.state.SetWaitTime(time.Now().Add(-time.Hour))
|
|
}
|