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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package lib_test
import (
"os"
"testing"
"time"
"github.com/roadrunner-server/informer/v4"
"github.com/roadrunner-server/resetter/v4"
"github.com/roadrunner-server/roadrunner/v2023/lib"
"github.com/stretchr/testify/assert"
)
func TestNewFailsOnMissingConfig(t *testing.T) {
_, err := lib.NewRR("config/file/does/not/exist/.rr.yaml", []string{}, lib.DefaultPluginsList())
assert.NotNil(t, err)
}
const testConfigWithVersion = `
version: '3'
server:
command: "php src/index.php"
relay: "pipes"
endure:
grace_period: 1s
`
const testConfig = `
server:
command: "php src/index.php"
relay: "pipes"
endure:
grace_period: 1s
`
func makeConfig(t *testing.T, configYaml string) string {
cfgFile := os.TempDir() + "/.rr.yaml"
err := os.WriteFile(cfgFile, []byte(configYaml), 0600)
assert.NoError(t, err)
return cfgFile
}
func TestNewWithOldConfig(t *testing.T) {
cfgFile := makeConfig(t, testConfig)
_, err := lib.NewRR(cfgFile, []string{}, lib.DefaultPluginsList())
assert.Error(t, err)
t.Cleanup(func() {
_ = os.Remove(cfgFile)
})
}
func TestNewWithConfig(t *testing.T) {
cfgFile := makeConfig(t, testConfigWithVersion)
rr, err := lib.NewRR(cfgFile, []string{}, lib.DefaultPluginsList())
assert.NoError(t, err)
assert.Equal(t, "3", rr.Version)
t.Cleanup(func() {
_ = os.Remove(cfgFile)
})
}
func TestServeStop(t *testing.T) {
cfgFile := makeConfig(t, testConfigWithVersion)
plugins := []any{
&informer.Plugin{},
&resetter.Plugin{},
}
rr, err := lib.NewRR(cfgFile, []string{}, plugins)
assert.NoError(t, err)
errchan := make(chan error, 1)
stopchan := make(chan struct{}, 1)
go func() {
errchan <- rr.Serve()
stopchan <- struct{}{}
}()
rr.Stop()
time.Sleep(time.Second * 2)
assert.Equal(t, struct{}{}, <-stopchan)
assert.Nil(t, <-errchan)
t.Cleanup(func() {
_ = os.Remove(cfgFile)
})
}
|