summaryrefslogtreecommitdiff
path: root/lib/roadrunner_test.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2022-07-15 16:51:40 +0200
committerValery Piashchynski <[email protected]>2022-07-15 16:51:40 +0200
commit15e583a25fd2ab486e93059d9ba98f447e3fedc5 (patch)
tree608e4eb6267cbaef85ffaaa38b7d23732de7ebfe /lib/roadrunner_test.go
parent487365f5f0eb93f123731fae9462b6a4e6035177 (diff)
update library name
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'lib/roadrunner_test.go')
-rw-r--r--lib/roadrunner_test.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/roadrunner_test.go b/lib/roadrunner_test.go
new file mode 100644
index 00000000..9406b7bf
--- /dev/null
+++ b/lib/roadrunner_test.go
@@ -0,0 +1,83 @@
+package lib_test
+
+import (
+ "os"
+ "testing"
+ "time"
+
+ "github.com/roadrunner-server/endure/pkg/fsm"
+ "github.com/roadrunner-server/informer/v2"
+ "github.com/roadrunner-server/resetter/v2"
+ "github.com/roadrunner-server/roadrunner/v2/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 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.Nil(t, err)
+
+ return cfgFile
+}
+
+func TestNewWithConfig(t *testing.T) {
+ cfgFile := makeConfig(t, testConfig)
+ rr, err := lib.NewRR(cfgFile, []string{}, lib.DefaultPluginsList())
+ assert.Nil(t, err)
+
+ assert.Equal(t, "2", string(rr.Version[0]))
+ assert.Equal(t, fsm.Initialized, rr.CurrentState())
+
+ t.Cleanup(func() {
+ _ = os.Remove(cfgFile)
+ })
+}
+
+func TestServeStop(t *testing.T) {
+ cfgFile := makeConfig(t, testConfig)
+ plugins := []interface{}{
+ &informer.Plugin{},
+ &resetter.Plugin{},
+ }
+ rr, err := lib.NewRR(cfgFile, []string{}, plugins)
+ assert.Nil(t, err)
+
+ errchan := make(chan error, 1)
+ stopchan := make(chan struct{}, 1)
+
+ go func() {
+ errchan <- rr.Serve()
+ stopchan <- struct{}{}
+ }()
+
+ assert.Equal(t, rr.CurrentState(), fsm.Initialized)
+
+ for rr.CurrentState() != fsm.Started {
+ time.Sleep(20 * time.Millisecond)
+ }
+
+ rr.Stop()
+ time.Sleep(time.Second * 2)
+
+ assert.Equal(t, fsm.Stopped, rr.CurrentState())
+ assert.Equal(t, struct{}{}, <-stopchan)
+ assert.Nil(t, <-errchan)
+
+ t.Cleanup(func() {
+ _ = os.Remove(cfgFile)
+ })
+}