diff options
author | Valery Piashchynski <[email protected]> | 2021-06-14 17:00:06 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-14 17:00:06 +0300 |
commit | 9748651763415c417eaa339920cba031d418fda6 (patch) | |
tree | ee860c0e959c34cd9092923acf503a2017b4713e | |
parent | 75ab1e16c64cfd0a6424fe4c546fdbc5e1b992dd (diff) |
- Add more tests
Signed-off-by: Valery Piashchynski <[email protected]>
-rw-r--r-- | codecov.yml | 1 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | plugins/websockets/plugin.go | 2 | ||||
-rw-r--r-- | tests/plugins/websockets/configs/.rr-websockets-redis-memory-local.yaml | 38 | ||||
-rw-r--r-- | tests/plugins/websockets/configs/.rr-websockets-redis-no-section.yaml | 34 | ||||
-rw-r--r-- | tests/plugins/websockets/websocket_plugin_test.go | 106 |
7 files changed, 183 insertions, 4 deletions
diff --git a/codecov.yml b/codecov.yml index da01f6f7..40040d8b 100644 --- a/codecov.yml +++ b/codecov.yml @@ -16,6 +16,7 @@ ignore: - "tests" - "plugins/metrics/config_test.go" - "plugins/websockets/storage/storage_test.go" + - "plugins/websockets/config.go" - "pkg/bst/bst_test.go" - "pkg/doc" - "pkg/pool/static_pool_test.go" @@ -21,7 +21,7 @@ require ( // SPIRAL ==== github.com/spiral/endure v1.0.2 github.com/spiral/errors v1.0.11 - github.com/spiral/goridge/v3 v3.1.3 + github.com/spiral/goridge/v3 v3.1.4 // =========== github.com/stretchr/testify v1.7.0 github.com/tklauser/go-sysconf v0.3.6 // indirect @@ -388,8 +388,8 @@ github.com/spiral/endure v1.0.2/go.mod h1:/mnduq57eBKgKCwpuLgUp8Fn/c3h6JgWybG+0h github.com/spiral/errors v1.0.10/go.mod h1:SwMSZVdZkkJVgXNNafccqOaxWg0XPzVU/dEdUEInE0o= github.com/spiral/errors v1.0.11 h1:TGG+t3mNouLuRW54Ph7nHo4X3u4WhbxqEQmnIybi7Go= github.com/spiral/errors v1.0.11/go.mod h1:SwMSZVdZkkJVgXNNafccqOaxWg0XPzVU/dEdUEInE0o= -github.com/spiral/goridge/v3 v3.1.3 h1:mjKLxWBmCN2ZErkA1mTkQAMbYjWQK8cb7DluQA/9wjU= -github.com/spiral/goridge/v3 v3.1.3/go.mod h1:swcWZW7nP+KU9rgyRf6w7CfNDCWRC/vePE2+AKtoqjk= +github.com/spiral/goridge/v3 v3.1.4 h1:5egVVTfaD1PO4MRgzU0yyog86pAh+JIOk7xhe7BtG40= +github.com/spiral/goridge/v3 v3.1.4/go.mod h1:swcWZW7nP+KU9rgyRf6w7CfNDCWRC/vePE2+AKtoqjk= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= diff --git a/plugins/websockets/plugin.go b/plugins/websockets/plugin.go index c53491b4..6dfe6ca3 100644 --- a/plugins/websockets/plugin.go +++ b/plugins/websockets/plugin.go @@ -90,7 +90,7 @@ func (p *Plugin) Init(cfg config.Configurer, log logger.Logger, server server.Se } func (p *Plugin) Serve() chan error { - errCh := make(chan error) + errCh := make(chan error, 1) const op = errors.Op("websockets_plugin_serve") err := p.initPubSubs() diff --git a/tests/plugins/websockets/configs/.rr-websockets-redis-memory-local.yaml b/tests/plugins/websockets/configs/.rr-websockets-redis-memory-local.yaml new file mode 100644 index 00000000..27eab557 --- /dev/null +++ b/tests/plugins/websockets/configs/.rr-websockets-redis-memory-local.yaml @@ -0,0 +1,38 @@ +rpc: + listen: tcp://127.0.0.1:6001 + +server: + command: "php ../../psr-worker-bench.php" + user: "" + group: "" + relay: "pipes" + relay_timeout: "20s" + +http: + address: 127.0.0.1:13235 + max_request_size: 1024 + middleware: [ "websockets" ] + trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ] + pool: + num_workers: 2 + max_jobs: 0 + allocate_timeout: 60s + destroy_timeout: 60s + + +websockets: + pubsubs: [ "redis", "memory" ] + redis: + addrs: + - "localhost:6379" + + path: "/ws" + +logs: + mode: development + level: error + +endure: + grace_period: 120s + print_graph: false + log_level: error diff --git a/tests/plugins/websockets/configs/.rr-websockets-redis-no-section.yaml b/tests/plugins/websockets/configs/.rr-websockets-redis-no-section.yaml new file mode 100644 index 00000000..fd125794 --- /dev/null +++ b/tests/plugins/websockets/configs/.rr-websockets-redis-no-section.yaml @@ -0,0 +1,34 @@ +rpc: + listen: tcp://127.0.0.1:6001 + +server: + command: "php ../../psr-worker-bench.php" + user: "" + group: "" + relay: "pipes" + relay_timeout: "20s" + +http: + address: 127.0.0.1:13235 + max_request_size: 1024 + middleware: [ "websockets" ] + trusted_subnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ] + pool: + num_workers: 2 + max_jobs: 0 + allocate_timeout: 60s + destroy_timeout: 60s + + +websockets: + pubsubs: [ "redis", "memory" ] + path: "/ws" + +logs: + mode: development + level: error + +endure: + grace_period: 120s + print_graph: false + log_level: error diff --git a/tests/plugins/websockets/websocket_plugin_test.go b/tests/plugins/websockets/websocket_plugin_test.go index 88828c5a..07ee5f12 100644 --- a/tests/plugins/websockets/websocket_plugin_test.go +++ b/tests/plugins/websockets/websocket_plugin_test.go @@ -214,6 +214,112 @@ func TestWSRedisAndMemory(t *testing.T) { wg.Wait() } +func TestWSRedisAndMemoryGlobal(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-websockets-redis-memory.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &rpcPlugin.Plugin{}, + &logger.ZapLogger{}, + &server.Plugin{}, + &redis.Plugin{}, + &websockets.Plugin{}, + &httpPlugin.Plugin{}, + &memory.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + ch, err := cont.Serve() + if err != nil { + t.Fatal(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 + } + } + }() + + time.Sleep(time.Second * 1) + t.Run("RPCWsMemoryPubAsync", RPCWsMemoryPubAsync) + t.Run("RPCWsMemory", RPCWsMemory) + t.Run("RPCWsRedis", RPCWsRedis) + + stopCh <- struct{}{} + + wg.Wait() +} + +func TestWSRedisNoSection(t *testing.T) { + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) + assert.NoError(t, err) + + cfg := &config.Viper{ + Path: "configs/.rr-websockets-redis-no-section.yaml", + Prefix: "rr", + } + + err = cont.RegisterAll( + cfg, + &rpcPlugin.Plugin{}, + &logger.ZapLogger{}, + &server.Plugin{}, + &redis.Plugin{}, + &websockets.Plugin{}, + &httpPlugin.Plugin{}, + &memory.Plugin{}, + ) + assert.NoError(t, err) + + err = cont.Init() + if err != nil { + t.Fatal(err) + } + + _, err = cont.Serve() + assert.Error(t, err) +} + func RPCWsMemoryPubAsync(t *testing.T) { da := websocket.Dialer{ Proxy: http.ProxyFromEnvironment, |