diff options
Diffstat (limited to 'tests')
20 files changed, 524 insertions, 53 deletions
diff --git a/tests/env/Dockerfile-elastic-mq.yaml b/tests/env/Dockerfile-elastic-mq.yaml index e1513450..75d8a8ff 100644 --- a/tests/env/Dockerfile-elastic-mq.yaml +++ b/tests/env/Dockerfile-elastic-mq.yaml @@ -1,8 +1,8 @@ FROM openjdk:16 -ADD https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-1.2.0.jar / +ADD https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-1.2.1.jar / COPY custom.conf / -ENTRYPOINT ["java", "-Dconfig.file=custom.conf", "-jar", "/elasticmq-server-1.2.0.jar"] +ENTRYPOINT ["java", "-Dconfig.file=custom.conf", "-jar", "/elasticmq-server-1.2.1.jar"] EXPOSE 9324 diff --git a/tests/env/docker-compose.yaml b/tests/env/docker-compose.yaml index d93bc5af..8ef2a99b 100644 --- a/tests/env/docker-compose.yaml +++ b/tests/env/docker-compose.yaml @@ -1,44 +1,44 @@ -version: '3' +version: "3" services: - memcached: - image: memcached:latest - ports: - - "127.0.0.1:11211:11211" - redis: - image: redis:6 - ports: - - "127.0.0.1:6379:6379" - redis2: - image: redis:6 - ports: - - "127.0.0.1:6378:6379" + memcached: + image: memcached:latest + ports: + - "127.0.0.1:11211:11211" + redis: + image: redis:6 + ports: + - "127.0.0.1:6379:6379" + redis2: + image: redis:6 + ports: + - "127.0.0.1:6378:6379" - toxicproxy: - image: shopify/toxiproxy - network_mode: "host" + toxicproxy: + image: ghcr.io/shopify/toxiproxy:latest + network_mode: host - beanstalk: - build: - context: . - dockerfile: Dockerfile-beanstalkd.yaml - ports: - - "127.0.0.1:11300:11300" + beanstalk: + build: + context: . + dockerfile: Dockerfile-beanstalkd.yaml + ports: + - "127.0.0.1:11300:11300" - sqs: - build: - context: . - dockerfile: Dockerfile-elastic-mq.yaml - ports: - - "127.0.0.1:9324:9324" + sqs: + build: + context: . + dockerfile: Dockerfile-elastic-mq.yaml + ports: + - "127.0.0.1:9324:9324" - rabbitmq: - image: rabbitmq:3-management - ports: - - "127.0.0.1:15672:15672" - - "127.0.0.1:5672:5672" + rabbitmq: + image: rabbitmq:3-management + ports: + - "127.0.0.1:15672:15672" + - "127.0.0.1:5672:5672" - prometheus: - image: prom/prometheus - ports: - - "9090:9090" + prometheus: + image: prom/prometheus + ports: + - "9090:9090"
\ No newline at end of file diff --git a/tests/plugins/grpc/configs/.rr-grpc-init.yaml b/tests/plugins/grpc/configs/.rr-grpc-init.yaml new file mode 100644 index 00000000..010e904e --- /dev/null +++ b/tests/plugins/grpc/configs/.rr-grpc-init.yaml @@ -0,0 +1,50 @@ +# GRPC service configuration +grpc: + # socket to listen + listen: "tcp://localhost:9001" + + # proto root file + proto: "test.proto" + + # max send limit (MB) + max_send_msg_size: 50 + + # max receive limit (MB) + max_recv_msg_size: 50 + + # MaxConnectionIdle is a duration for the amount of time after which an + # idle connection would be closed by sending a GoAway. Idleness duration is + # defined since the most recent time the number of outstanding RPCs became + # zero or the connection establishment. + max_connection_idle: 0s + + # MaxConnectionAge is a duration for the maximum amount of time a + # connection may exist before it will be closed by sending a GoAway. A + # random jitter of +/-10% will be added to MaxConnectionAge to spread out + # connection storms. + max_connection_age: 0s + + # MaxConnectionAgeGrace is an additive period after MaxConnectionAge after + # which the connection will be forcibly closed. + max_connection_age_grace: 0s + + # MaxConnectionAgeGrace is an additive period after MaxConnectionAge after + # which the connection will be forcibly closed. + max_concurrent_streams: 10 + + # After a duration of this time if the server doesn't see any activity it + # pings the client to see if the transport is still alive. + # If set below 1s, a minimum value of 1s will be used instead. + ping_time: 1s + + # After having pinged for keepalive check, the server waits for a duration + # of Timeout and if no activity is seen even after that the connection is + # closed. + timeout: 200s + + # Usual workers pool configuration + pool: + num_workers: 2 + max_jobs: 0 + allocate_timeout: 60s + destroy_timeout: 60 diff --git a/tests/plugins/grpc/grpc_plugin_test.go b/tests/plugins/grpc/grpc_plugin_test.go new file mode 100644 index 00000000..85dd5723 --- /dev/null +++ b/tests/plugins/grpc/grpc_plugin_test.go @@ -0,0 +1,7 @@ +package grpc_test + +import "testing" + +func GrpcInit(t *testing.T) { + +} diff --git a/tests/plugins/grpc/plugin_test.go b/tests/plugins/grpc/plugin_test.go new file mode 100644 index 00000000..cfbe0121 --- /dev/null +++ b/tests/plugins/grpc/plugin_test.go @@ -0,0 +1,178 @@ +package grpc + +import ( + "io/ioutil" + "os" + "os/exec" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func init() { + err := build() + if err != nil { + panic(err) + } +} + +func build() error { + cmd := exec.Command("go", "build", "-o", "plugin", "../../../plugins/grpc/protoc_plugins/protoc-gen-php-grpc") + return cmd.Run() +} + +func protoc(t *testing.T, args []string) { + cmd := exec.Command("protoc", "--plugin=protoc-gen-php-grpc=./plugin") + cmd.Args = append(cmd.Args, args...) + out, err := cmd.CombinedOutput() + + if len(out) > 0 || err != nil { + t.Log("RUNNING: ", strings.Join(cmd.Args, " ")) + } + + if len(out) > 0 { + t.Log(string(out)) + } + + if err != nil { + t.Fatalf("protoc: %v", err) + } +} + +func Test_Simple(t *testing.T) { + workdir, _ := os.Getwd() + tmpdir, err := ioutil.TempDir("", "proto-test") + require.NoError(t, err) + + defer func() { + assert.NoError(t, os.RemoveAll(tmpdir)) + }() + + args := []string{ + "-Itestdata", + "--php-grpc_out=" + tmpdir, + "simple/simple.proto", + } + + protoc(t, args) + + assertEqualFiles( + t, + workdir+"/testdata/simple/TestSimple/SimpleServiceInterface.php", + tmpdir+"/TestSimple/SimpleServiceInterface.php", + ) +} + +func Test_PhpNamespaceOption(t *testing.T) { + workdir, _ := os.Getwd() + tmpdir, err := ioutil.TempDir("", "proto-test") + require.NoError(t, err) + + defer func() { + assert.NoError(t, os.RemoveAll(tmpdir)) + }() + + args := []string{ + "-Itestdata", + "--php-grpc_out=" + tmpdir, + "php_namespace/service.proto", + } + protoc(t, args) + + assertEqualFiles( + t, + workdir+"/testdata/php_namespace/Test/CustomNamespace/ServiceInterface.php", + tmpdir+"/Test/CustomNamespace/ServiceInterface.php", + ) +} + +func Test_UseImportedMessage(t *testing.T) { + workdir, _ := os.Getwd() + tmpdir, err := ioutil.TempDir("", "proto-test") + require.NoError(t, err) + + defer func() { + assert.NoError(t, os.RemoveAll(tmpdir)) + }() + + args := []string{ + "-Itestdata", + "--php-grpc_out=" + tmpdir, + "import/service.proto", + } + protoc(t, args) + + assertEqualFiles( + t, + workdir+"/testdata/import/Import/ServiceInterface.php", + tmpdir+"/Import/ServiceInterface.php", + ) +} + +func Test_PhpNamespaceOptionInUse(t *testing.T) { + workdir, _ := os.Getwd() + tmpdir, err := ioutil.TempDir("", "proto-test") + require.NoError(t, err) + + defer func() { + assert.NoError(t, os.RemoveAll(tmpdir)) + }() + + args := []string{ + "-Itestdata", + "--php-grpc_out=" + tmpdir, + "import_custom/service.proto", + } + protoc(t, args) + + assertEqualFiles( + t, + workdir+"/testdata/import_custom/Test/CustomImport/ServiceInterface.php", + tmpdir+"/Test/CustomImport/ServiceInterface.php", + ) +} + +func Test_UseOfGoogleEmptyMessage(t *testing.T) { + workdir, _ := os.Getwd() + tmpdir, err := ioutil.TempDir("", "proto-test") + require.NoError(t, err) + + defer func() { + assert.NoError(t, os.RemoveAll(tmpdir)) + }() + + args := []string{ + "-Itestdata", + "--php-grpc_out=" + tmpdir, + "use_empty/service.proto", + } + protoc(t, args) + + assertEqualFiles( + t, + workdir+"/testdata/use_empty/Test/ServiceInterface.php", + tmpdir+"/Test/ServiceInterface.php", + ) + + assert.NoError(t, os.RemoveAll("plugin")) +} + +func assertEqualFiles(t *testing.T, original, generated string) { + assert.FileExists(t, generated) + + originalData, err := ioutil.ReadFile(original) + if err != nil { + t.Fatal("Can't find original file for comparison") + } + + generatedData, err := ioutil.ReadFile(generated) + if err != nil { + t.Fatal("Can't find generated file for comparison") + } + + // every OS has a special boy + r := strings.NewReplacer("\r\n", "", "\n", "") + assert.Equal(t, r.Replace(string(originalData)), r.Replace(string(generatedData))) +} diff --git a/tests/plugins/grpc/testdata/import/Import/ServiceInterface.php b/tests/plugins/grpc/testdata/import/Import/ServiceInterface.php new file mode 100644 index 00000000..13e58daf --- /dev/null +++ b/tests/plugins/grpc/testdata/import/Import/ServiceInterface.php @@ -0,0 +1,32 @@ +<?php +# Generated by the protocol buffer compiler (spiral/php-grpc). DO NOT EDIT! +# source: import/service.proto + +namespace Import; + +use Spiral\GRPC; +use Import\Sub; + +interface ServiceInterface extends GRPC\ServiceInterface +{ + // GRPC specific service name. + public const NAME = "import.Service"; + + /** + * @param GRPC\ContextInterface $ctx + * @param Message $in + * @return Message + * + * @throws GRPC\Exception\InvokeException + */ + public function SimpleMethod(GRPC\ContextInterface $ctx, Message $in): Message; + + /** + * @param GRPC\ContextInterface $ctx + * @param Sub\Message $in + * @return Sub\Message + * + * @throws GRPC\Exception\InvokeException + */ + public function ImportMethod(GRPC\ContextInterface $ctx, Sub\Message $in): Sub\Message; +} diff --git a/tests/plugins/grpc/testdata/import/service.proto b/tests/plugins/grpc/testdata/import/service.proto new file mode 100644 index 00000000..5d888f09 --- /dev/null +++ b/tests/plugins/grpc/testdata/import/service.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package import; + +import "import/sub/message.proto"; + +service Service { + rpc SimpleMethod (Message) returns (Message) { + } + + rpc ImportMethod (import.sub.Message) returns (import.sub.Message) { + } +} + +message Message { + int64 id = 1; +}
\ No newline at end of file diff --git a/tests/plugins/grpc/testdata/import/sub/message.proto b/tests/plugins/grpc/testdata/import/sub/message.proto new file mode 100644 index 00000000..1db0313b --- /dev/null +++ b/tests/plugins/grpc/testdata/import/sub/message.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +package import.sub; + +message Message { + int64 id = 1; +}
\ No newline at end of file diff --git a/tests/plugins/grpc/testdata/import_custom/Test/CustomImport/ServiceInterface.php b/tests/plugins/grpc/testdata/import_custom/Test/CustomImport/ServiceInterface.php new file mode 100644 index 00000000..b010ce4f --- /dev/null +++ b/tests/plugins/grpc/testdata/import_custom/Test/CustomImport/ServiceInterface.php @@ -0,0 +1,32 @@ +<?php +# Generated by the protocol buffer compiler (spiral/php-grpc). DO NOT EDIT! +# source: import_custom/service.proto + +namespace Test\CustomImport; + +use Spiral\GRPC; +use Test\CustomImport\Message; + +interface ServiceInterface extends GRPC\ServiceInterface +{ + // GRPC specific service name. + public const NAME = "import.Service"; + + /** + * @param GRPC\ContextInterface $ctx + * @param Message $in + * @return Message + * + * @throws GRPC\Exception\InvokeException + */ + public function SimpleMethod(GRPC\ContextInterface $ctx, Message $in): Message; + + /** + * @param GRPC\ContextInterface $ctx + * @param Message\Message $in + * @return Message\Message + * + * @throws GRPC\Exception\InvokeException + */ + public function ImportMethod(GRPC\ContextInterface $ctx, Message\Message $in): Message\Message; +} diff --git a/tests/plugins/grpc/testdata/import_custom/service.proto b/tests/plugins/grpc/testdata/import_custom/service.proto new file mode 100644 index 00000000..872aaae3 --- /dev/null +++ b/tests/plugins/grpc/testdata/import_custom/service.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package import; + +option php_namespace = "Test\\CustomImport"; + +import "import_custom/sub/message.proto"; + +service Service { + rpc SimpleMethod (Message) returns (Message) { + } + + rpc ImportMethod (import.sub.Message) returns (import.sub.Message) { + } +} + +message Message { + int64 id = 1; +}
\ No newline at end of file diff --git a/tests/plugins/grpc/testdata/import_custom/sub/message.proto b/tests/plugins/grpc/testdata/import_custom/sub/message.proto new file mode 100644 index 00000000..5d722ca3 --- /dev/null +++ b/tests/plugins/grpc/testdata/import_custom/sub/message.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package import.sub; +option php_namespace = "Test\\CustomImport\\Message"; + + +service Service { + rpc AnotherMethod (Message) returns (Message) { + } +} + +message Message { + int64 id = 1; +}
\ No newline at end of file diff --git a/tests/plugins/grpc/testdata/php_namespace/Test/CustomNamespace/ServiceInterface.php b/tests/plugins/grpc/testdata/php_namespace/Test/CustomNamespace/ServiceInterface.php new file mode 100644 index 00000000..2090ba97 --- /dev/null +++ b/tests/plugins/grpc/testdata/php_namespace/Test/CustomNamespace/ServiceInterface.php @@ -0,0 +1,22 @@ +<?php +# Generated by the protocol buffer compiler (spiral/php-grpc). DO NOT EDIT! +# source: php_namespace/service.proto + +namespace Test\CustomNamespace; + +use Spiral\GRPC; + +interface ServiceInterface extends GRPC\ServiceInterface +{ + // GRPC specific service name. + public const NAME = "testPhpNamespace.Service"; + + /** + * @param GRPC\ContextInterface $ctx + * @param SimpleMessage $in + * @return SimpleMessage + * + * @throws GRPC\Exception\InvokeException + */ + public function SimpleMethod(GRPC\ContextInterface $ctx, SimpleMessage $in): SimpleMessage; +} diff --git a/tests/plugins/grpc/testdata/php_namespace/service.proto b/tests/plugins/grpc/testdata/php_namespace/service.proto new file mode 100644 index 00000000..a3bfa3c0 --- /dev/null +++ b/tests/plugins/grpc/testdata/php_namespace/service.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package testPhpNamespace; + +option php_namespace = "Test\\CustomNamespace"; + +service Service { + rpc SimpleMethod (SimpleMessage) returns (SimpleMessage) { + } +} + +message SimpleMessage { + int32 id = 1; + string name = 2; +}
\ No newline at end of file diff --git a/tests/plugins/grpc/testdata/simple/TestSimple/SimpleServiceInterface.php b/tests/plugins/grpc/testdata/simple/TestSimple/SimpleServiceInterface.php new file mode 100644 index 00000000..f9e84bf7 --- /dev/null +++ b/tests/plugins/grpc/testdata/simple/TestSimple/SimpleServiceInterface.php @@ -0,0 +1,22 @@ +<?php +# Generated by the protocol buffer compiler (spiral/php-grpc). DO NOT EDIT! +# source: simple/simple.proto + +namespace TestSimple; + +use Spiral\GRPC; + +interface SimpleServiceInterface extends GRPC\ServiceInterface +{ + // GRPC specific service name. + public const NAME = "testSimple.SimpleService"; + + /** + * @param GRPC\ContextInterface $ctx + * @param SimpleMessage $in + * @return SimpleMessage + * + * @throws GRPC\Exception\InvokeException + */ + public function SimpleMethod(GRPC\ContextInterface $ctx, SimpleMessage $in): SimpleMessage; +} diff --git a/tests/plugins/grpc/testdata/simple/simple.proto b/tests/plugins/grpc/testdata/simple/simple.proto new file mode 100644 index 00000000..aca3c1d9 --- /dev/null +++ b/tests/plugins/grpc/testdata/simple/simple.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package testSimple; + +service SimpleService { + rpc SimpleMethod (SimpleMessage) returns (SimpleMessage) { + } +} + +message SimpleMessage { + int32 id = 1; + string name = 2; +}
\ No newline at end of file diff --git a/tests/plugins/grpc/testdata/use_empty/Test/ServiceInterface.php b/tests/plugins/grpc/testdata/use_empty/Test/ServiceInterface.php new file mode 100644 index 00000000..fe6d345a --- /dev/null +++ b/tests/plugins/grpc/testdata/use_empty/Test/ServiceInterface.php @@ -0,0 +1,23 @@ +<?php +# Generated by the protocol buffer compiler (spiral/php-grpc). DO NOT EDIT! +# source: use_empty/service.proto + +namespace Test; + +use Spiral\GRPC; +use Google\Protobuf; + +interface ServiceInterface extends GRPC\ServiceInterface +{ + // GRPC specific service name. + public const NAME = "test.Service"; + + /** + * @param GRPC\ContextInterface $ctx + * @param Protobuf\GPBEmpty $in + * @return Protobuf\GPBEmpty + * + * @throws GRPC\Exception\InvokeException + */ + public function Test(GRPC\ContextInterface $ctx, Protobuf\GPBEmpty $in): Protobuf\GPBEmpty; +} diff --git a/tests/plugins/grpc/testdata/use_empty/service.proto b/tests/plugins/grpc/testdata/use_empty/service.proto new file mode 100644 index 00000000..8c68d8d3 --- /dev/null +++ b/tests/plugins/grpc/testdata/use_empty/service.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package test; + +import "google/protobuf/empty.proto"; + +service Service { + rpc Test (google.protobuf.Empty) returns (google.protobuf.Empty) { + } +}
\ No newline at end of file diff --git a/tests/plugins/jobs/jobs_with_toxics_test.go b/tests/plugins/jobs/jobs_with_toxics_test.go index 80fed8eb..84fbec48 100644 --- a/tests/plugins/jobs/jobs_with_toxics_test.go +++ b/tests/plugins/jobs/jobs_with_toxics_test.go @@ -27,10 +27,18 @@ import ( func TestDurabilityAMQP(t *testing.T) { client := toxiproxy.NewClient("127.0.0.1:8474") + proxies, err := client.Proxies() + require.NoError(t, err) + + for p := range proxies { + _ = proxies[p].Delete() + } - _, err := client.CreateProxy("redial", "127.0.0.1:23679", "127.0.0.1:5672") + proxy, err := client.CreateProxy("redial", "127.0.0.1:23679", "127.0.0.1:5672") require.NoError(t, err) - defer deleteProxy("redial", t) + defer func() { + _ = proxy.Delete() + }() cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) require.NoError(t, err) diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go index 05ca2d53..e077f0bc 100644 --- a/tests/plugins/logger/logger_test.go +++ b/tests/plugins/logger/logger_test.go @@ -346,18 +346,6 @@ func TestFileLogger(t *testing.T) { wg.Wait() } -func httpEcho(t *testing.T) { - req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:54224?hello=world", nil) - assert.NoError(t, err) - - r, err := http.DefaultClient.Do(req) - assert.NoError(t, err) - assert.Equal(t, http.StatusCreated, r.StatusCode) - - err = r.Body.Close() - assert.NoError(t, err) -} - func TestMarshalObjectLogging(t *testing.T) { container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel)) if err != nil { @@ -428,3 +416,15 @@ func TestMarshalObjectLogging(t *testing.T) { stopCh <- struct{}{} wg.Wait() } + +func httpEcho(t *testing.T) { + req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:54224?hello=world", nil) + assert.NoError(t, err) + + r, err := http.DefaultClient.Do(req) + assert.NoError(t, err) + assert.Equal(t, http.StatusCreated, r.StatusCode) + + err = r.Body.Close() + assert.NoError(t, err) +} diff --git a/tests/script.sh b/tests/script.sh new file mode 100755 index 00000000..746fb768 --- /dev/null +++ b/tests/script.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +php ../../../tests/client.php echo pipes
\ No newline at end of file |