summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-02-16 12:53:34 +0300
committerValery Piashchynski <[email protected]>2021-02-16 12:53:34 +0300
commitac159557f3a31e53e0c76c4196b0e42e1e71aa52 (patch)
tree3e26d5fa6f022d1cebd2da7bc9ccb832009a29f5 /tests
parent69622100a1c95656f977638f75d8cea81afc0d4a (diff)
Update logger plugin. Now it's optional
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/plugins/logger/configs/.rr-no-logger.yaml0
-rw-r--r--tests/plugins/logger/configs/.rr-no-logger2.yaml21
-rw-r--r--tests/plugins/logger/configs/.rr.yaml (renamed from tests/plugins/logger/.rr.yaml)0
-rw-r--r--tests/plugins/logger/logger_test.go125
4 files changed, 142 insertions, 4 deletions
diff --git a/tests/plugins/logger/configs/.rr-no-logger.yaml b/tests/plugins/logger/configs/.rr-no-logger.yaml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/plugins/logger/configs/.rr-no-logger.yaml
diff --git a/tests/plugins/logger/configs/.rr-no-logger2.yaml b/tests/plugins/logger/configs/.rr-no-logger2.yaml
new file mode 100644
index 00000000..1211b7ad
--- /dev/null
+++ b/tests/plugins/logger/configs/.rr-no-logger2.yaml
@@ -0,0 +1,21 @@
+rpc:
+ listen: tcp://127.0.0.1:6001
+
+server:
+ command: "php ../../http/client.php echo pipes"
+ user: ""
+ group: ""
+ env:
+ "RR_HTTP": "true"
+ relay: "pipes"
+ relay_timeout: "20s"
+
+http:
+ debug: true
+ address: 127.0.0.1:18945
+ max_request_size: 1024
+ pool:
+ num_workers: 2
+ max_jobs: 0
+ allocate_timeout: 60s
+ destroy_timeout: 60s \ No newline at end of file
diff --git a/tests/plugins/logger/.rr.yaml b/tests/plugins/logger/configs/.rr.yaml
index 5ab359d3..5ab359d3 100644
--- a/tests/plugins/logger/.rr.yaml
+++ b/tests/plugins/logger/configs/.rr.yaml
diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go
index 63f233ee..5be76b7a 100644
--- a/tests/plugins/logger/logger_test.go
+++ b/tests/plugins/logger/logger_test.go
@@ -8,7 +8,10 @@ import (
endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
+ "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/plugins/rpc"
+ "github.com/spiral/roadrunner/v2/plugins/server"
"github.com/stretchr/testify/assert"
)
@@ -19,22 +22,136 @@ func TestLogger(t *testing.T) {
}
// config plugin
vp := &config.Viper{}
- vp.Path = ".rr.yaml"
+ vp.Path = "configs/.rr.yaml"
vp.Prefix = "rr"
- err = container.Register(vp)
+
+ err = container.RegisterAll(
+ vp,
+ &Plugin{},
+ &logger.ZapLogger{},
+ )
+ assert.NoError(t, err)
+
+ err = container.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ errCh, err := container.Serve()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // stop by CTRL+C
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+
+ stopCh := make(chan struct{}, 1)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-errCh:
+ assert.NoError(t, e.Error)
+ assert.NoError(t, container.Stop())
+ return
+ case <-c:
+ err = container.Stop()
+ assert.NoError(t, err)
+ return
+ case <-stopCh:
+ assert.NoError(t, container.Stop())
+ return
+ }
+ }
+ }()
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+func TestLoggerNoConfig(t *testing.T) {
+ container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.DebugLevel))
+ if err != nil {
+ t.Fatal(err)
+ }
+ // config plugin
+ vp := &config.Viper{}
+ vp.Path = "configs/.rr-no-logger.yaml"
+ vp.Prefix = "rr"
+
+ err = container.RegisterAll(
+ vp,
+ &Plugin{},
+ &logger.ZapLogger{},
+ )
+ assert.NoError(t, err)
+
+ err = container.Init()
if err != nil {
t.Fatal(err)
}
- err = container.Register(&Plugin{})
+ errCh, err := container.Serve()
if err != nil {
t.Fatal(err)
}
- err = container.Register(&logger.ZapLogger{})
+ // stop by CTRL+C
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+
+ stopCh := make(chan struct{}, 1)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-errCh:
+ assert.NoError(t, e.Error)
+ assert.NoError(t, container.Stop())
+ return
+ case <-c:
+ err = container.Stop()
+ assert.NoError(t, err)
+ return
+ case <-stopCh:
+ assert.NoError(t, container.Stop())
+ return
+ }
+ }
+ }()
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+// Should no panic
+func TestLoggerNoConfig2(t *testing.T) {
+ container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.DebugLevel))
if err != nil {
t.Fatal(err)
}
+ // config plugin
+ vp := &config.Viper{}
+ vp.Path = "configs/.rr-no-logger2.yaml"
+ vp.Prefix = "rr"
+
+ err = container.RegisterAll(
+ vp,
+ &rpc.Plugin{},
+ &logger.ZapLogger{},
+ &http.Plugin{},
+ &server.Plugin{},
+ )
+ assert.NoError(t, err)
err = container.Init()
if err != nil {