summaryrefslogtreecommitdiff
path: root/plugins/checker
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-03 14:11:40 +0300
committerValery Piashchynski <[email protected]>2020-12-03 14:11:40 +0300
commitc5aa774e5ad961929b4dfbe16f48a3747e2190a6 (patch)
tree713509d954f6ba91c573dd35adda38e532300d3d /plugins/checker
parentdbcd8647d878abff04636f77eed87243b3758abb (diff)
Add status request to the test
Diffstat (limited to 'plugins/checker')
-rw-r--r--plugins/checker/plugin.go15
-rwxr-xr-xplugins/checker/tests/configs/.rr-checker-init.yaml2
-rw-r--r--plugins/checker/tests/plugin_test.go24
3 files changed, 36 insertions, 5 deletions
diff --git a/plugins/checker/plugin.go b/plugins/checker/plugin.go
index 9f4c1fd8..c72cc615 100644
--- a/plugins/checker/plugin.go
+++ b/plugins/checker/plugin.go
@@ -3,6 +3,7 @@ package checker
import (
"fmt"
"net/http"
+ "time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
@@ -36,10 +37,13 @@ func (c *Plugin) Init(log log.Logger, cfg config.Configurer) error {
return nil
}
-// localhost:88294/status/all
func (c *Plugin) Serve() chan error {
errCh := make(chan error, 1)
- c.server = fiber.New()
+ c.server = fiber.New(fiber.Config{
+ ReadTimeout: time.Second * 5,
+ WriteTimeout: time.Second * 5,
+ IdleTimeout: time.Second * 5,
+ })
c.server.Group("/v1", c.healthHandler)
c.server.Use(logger.New())
c.server.Use("/health", c.healthHandler)
@@ -55,7 +59,12 @@ func (c *Plugin) Serve() chan error {
}
func (c *Plugin) Stop() error {
- return c.server.Shutdown()
+ const op = errors.Op("checker stop")
+ err := c.server.Shutdown()
+ if err != nil {
+ return errors.E(op, err)
+ }
+ return nil
}
// Reset named service.
diff --git a/plugins/checker/tests/configs/.rr-checker-init.yaml b/plugins/checker/tests/configs/.rr-checker-init.yaml
index ba008853..87e639ef 100755
--- a/plugins/checker/tests/configs/.rr-checker-init.yaml
+++ b/plugins/checker/tests/configs/.rr-checker-init.yaml
@@ -16,7 +16,7 @@ status:
http:
debug: true
- address: 127.0.0.1:18903
+ address: 127.0.0.1:11933
maxRequestSize: 1024
middleware: [ "" ]
uploads:
diff --git a/plugins/checker/tests/plugin_test.go b/plugins/checker/tests/plugin_test.go
index 58cb45a0..1cc1af47 100644
--- a/plugins/checker/tests/plugin_test.go
+++ b/plugins/checker/tests/plugin_test.go
@@ -1,6 +1,8 @@
package tests
import (
+ "io/ioutil"
+ "net/http"
"os"
"os/signal"
"sync"
@@ -49,7 +51,7 @@ func TestStatusInit(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
- tt := time.NewTimer(time.Second * 5)
+ tt := time.NewTimer(time.Second * 10)
go func() {
defer wg.Done()
@@ -78,5 +80,25 @@ func TestStatusInit(t *testing.T) {
}
}()
+ time.Sleep(time.Second)
+ t.Run("CheckerGetStatus", checkHttpStatus)
wg.Wait()
}
+
+const resp = `Service: http: Status: 200
+Service: rpc not found`
+
+func checkHttpStatus(t *testing.T) {
+ req, err := http.NewRequest("GET", "http://127.0.0.1:34333/v1/health?plugin=http&plugin=rpc", nil)
+ assert.NoError(t, err)
+
+ r, err := http.DefaultClient.Do(req)
+ assert.NoError(t, err)
+ b, err := ioutil.ReadAll(r.Body)
+ assert.NoError(t, err)
+ assert.Equal(t, 200, r.StatusCode)
+ assert.Equal(t, resp, string(b))
+
+ err = r.Body.Close()
+ assert.NoError(t, err)
+}