forked from php/frankenphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaling_test.go
More file actions
63 lines (49 loc) · 1.47 KB
/
scaling_test.go
File metadata and controls
63 lines (49 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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))
}