summaryrefslogtreecommitdiff
path: root/tests/plugins/logger
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-04-04 21:02:15 +0300
committerValery Piashchynski <[email protected]>2021-04-04 21:02:15 +0300
commit5efb7849b468a7564d48bcf70653b780520905b7 (patch)
tree77d9a6fa865d73bb7d794959704753258312341d /tests/plugins/logger
parentcc56299b877f3fbbae1e3368d98804d06564a424 (diff)
parent899936387791bc4c73da5374484c3609b51981a2 (diff)
Merge remote-tracking branch 'origin/master' into feature/readiness_probe_healthcheck_endpoint
# Conflicts: # go.sum
Diffstat (limited to 'tests/plugins/logger')
-rw-r--r--tests/plugins/logger/configs/.rr-raw-mode.yaml15
-rw-r--r--tests/plugins/logger/logger_test.go74
-rw-r--r--tests/plugins/logger/plugin.go7
3 files changed, 96 insertions, 0 deletions
diff --git a/tests/plugins/logger/configs/.rr-raw-mode.yaml b/tests/plugins/logger/configs/.rr-raw-mode.yaml
new file mode 100644
index 00000000..fba25945
--- /dev/null
+++ b/tests/plugins/logger/configs/.rr-raw-mode.yaml
@@ -0,0 +1,15 @@
+server:
+ command: "php ../../raw-error.php"
+ relay: "pipes"
+
+http:
+ address: 127.0.0.1:34999
+ max_requestSize: 1024
+ pool:
+ num_workers: 1
+ max_jobs: 0
+ allocate_timeout: 10s
+ destroy_timeout: 10s
+
+logs:
+ mode: raw
diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go
index 7f378026..d2877781 100644
--- a/tests/plugins/logger/logger_test.go
+++ b/tests/plugins/logger/logger_test.go
@@ -4,14 +4,17 @@ import (
"os"
"os/signal"
"sync"
+ "syscall"
"testing"
+ "github.com/golang/mock/gomock"
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/spiral/roadrunner/v2/tests/mocks"
"github.com/stretchr/testify/assert"
)
@@ -74,6 +77,77 @@ func TestLogger(t *testing.T) {
wg.Wait()
}
+func TestLoggerRawErr(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
+ assert.NoError(t, err)
+
+ // config plugin
+ cfg := &config.Viper{}
+ cfg.Path = "configs/.rr-raw-mode.yaml"
+ cfg.Prefix = "rr"
+
+ controller := gomock.NewController(t)
+ mockLogger := mocks.NewMockLogger(controller)
+
+ mockLogger.EXPECT().Debug("worker destructed", "pid", gomock.Any()).MinTimes(1)
+ mockLogger.EXPECT().Info("{\"field\": \"value\"}").MinTimes(1)
+ mockLogger.EXPECT().Debug("worker constructed", "pid", gomock.Any()).MinTimes(1)
+
+ err = cont.RegisterAll(
+ cfg,
+ mockLogger,
+ &server.Plugin{},
+ &http.Plugin{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ch, err := cont.Serve()
+ assert.NoError(t, err)
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ stopCh := make(chan struct{}, 1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-stopCh:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
func TestLoggerNoConfig(t *testing.T) {
container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
if err != nil {
diff --git a/tests/plugins/logger/plugin.go b/tests/plugins/logger/plugin.go
index 9ddf9ec9..aa62f2b3 100644
--- a/tests/plugins/logger/plugin.go
+++ b/tests/plugins/logger/plugin.go
@@ -1,6 +1,8 @@
package logger
import (
+ "strings"
+
"github.com/spiral/errors"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/logger"
@@ -28,6 +30,11 @@ func (p1 *Plugin) Serve() chan error {
p1.log.Info("error", "test")
p1.log.Debug("error", "test")
p1.log.Warn("error", "test")
+
+ // test the `raw` mode
+ messageJSON := []byte(`{"field": "value"}`)
+ p1.log.Debug(strings.TrimRight(string(messageJSON), " \n\t"))
+
return errCh
}