-
-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathscaling_test.go
60 lines (47 loc) · 1.38 KB
/
scaling_test.go
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
package frankenphp
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
func TestScaleARegularThreadUpAndDown(t *testing.T) {
assert.NoError(t, Init(
WithNumThreads(1),
WithMaxThreads(2),
WithLogger(zap.NewNop()),
))
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) {
workerPath := testDataPath + "/transition-worker-1.php"
assert.NoError(t, Init(
WithNumThreads(2),
WithMaxThreads(3),
WithWorkers(workerPath, 1, map[string]string{}, []string{}),
WithLogger(zap.NewNop()),
))
autoScaledThread := phpThreads[2]
// scale up
scaleWorkerThread(workers[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()
}