summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-03-26 20:08:18 +0300
committerValery Piashchynski <[email protected]>2020-03-26 20:08:18 +0300
commit58f10f257be50d95e6b227d99d35a3655b878847 (patch)
treed0e91c991db40f0571301f282deedc39f83b4b86 /service
parentf9c5ecbb31c9c8f63c5e793abb4afbf7311f33af (diff)
Total backoff for headers service tests
Diffstat (limited to 'service')
-rw-r--r--service/headers/service_test.go152
1 files changed, 60 insertions, 92 deletions
diff --git a/service/headers/service_test.go b/service/headers/service_test.go
index 7a28289c..e8d143d8 100644
--- a/service/headers/service_test.go
+++ b/service/headers/service_test.go
@@ -36,16 +36,20 @@ func (cfg *testCfg) Unmarshal(out interface{}) error {
}
func Test_RequestHeaders(t *testing.T) {
- logger, _ := test.NewNullLogger()
- logger.SetLevel(logrus.DebugLevel)
+ bkoff := backoff.NewExponentialBackOff()
+ bkoff.MaxElapsedTime = time.Second * 15
+
+ err := backoff.Retry(func() error {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
- c := service.NewContainer(logger)
- c.Register(rrhttp.ID, &rrhttp.Service{})
- c.Register(ID, &Service{})
+ c := service.NewContainer(logger)
+ c.Register(rrhttp.ID, &rrhttp.Service{})
+ c.Register(ID, &Service{})
- assert.NoError(t, c.Init(&testCfg{
- headers: `{"request":{"input": "custom-header"}}`,
- httpCfg: `{
+ assert.NoError(t, c.Init(&testCfg{
+ headers: `{"request":{"input": "custom-header"}}`,
+ httpCfg: `{
"enable": true,
"address": ":6078",
"maxRequestSize": 1024,
@@ -60,19 +64,16 @@ func Test_RequestHeaders(t *testing.T) {
}
}`}))
- go func() {
- err := c.Serve()
- if err != nil {
- t.Errorf("error during Serve: error %v", err)
- }
- }()
- time.Sleep(time.Millisecond * 100)
- defer c.Stop()
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during Serve: error %v", err)
+ }
+ }()
- bkoff := backoff.NewExponentialBackOff()
- bkoff.MaxElapsedTime = time.Second * 15
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
- err := backoff.Retry(func() error {
req, err := http.NewRequest("GET", "http://localhost:6078?hello=value", nil)
if err != nil {
return err
@@ -105,39 +106,6 @@ func Test_RequestHeaders(t *testing.T) {
}
func Test_ResponseHeaders(t *testing.T) {
- logger, _ := test.NewNullLogger()
- logger.SetLevel(logrus.DebugLevel)
-
- c := service.NewContainer(logger)
- c.Register(rrhttp.ID, &rrhttp.Service{})
- c.Register(ID, &Service{})
-
- assert.NoError(t, c.Init(&testCfg{
- headers: `{"response":{"output": "output-header"},"request":{"input": "custom-header"}}`,
- httpCfg: `{
- "enable": true,
- "address": ":6079",
- "maxRequestSize": 1024,
- "workers":{
- "command": "php ../../tests/http/client.php header pipes",
- "relay": "pipes",
- "pool": {
- "numWorkers": 1,
- "allocateTimeout": 10000000,
- "destroyTimeout": 10000000
- }
- }
- }`}))
-
- go func() {
- err := c.Serve()
- if err != nil {
- t.Errorf("error during the Serve: error %v", err)
- }
- }()
- time.Sleep(time.Millisecond * 100)
- defer c.Stop()
-
bkoff := backoff.NewExponentialBackOff()
bkoff.MaxElapsedTime = time.Second * 15
@@ -175,15 +143,19 @@ func Test_ResponseHeaders(t *testing.T) {
}
func TestCORS_OPTIONS(t *testing.T) {
- logger, _ := test.NewNullLogger()
- logger.SetLevel(logrus.DebugLevel)
+ bkoff := backoff.NewExponentialBackOff()
+ bkoff.MaxElapsedTime = time.Second * 15
+
+ err := backoff.Retry(func() error {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
- c := service.NewContainer(logger)
- c.Register(rrhttp.ID, &rrhttp.Service{})
- c.Register(ID, &Service{})
+ c := service.NewContainer(logger)
+ c.Register(rrhttp.ID, &rrhttp.Service{})
+ c.Register(ID, &Service{})
- assert.NoError(t, c.Init(&testCfg{
- headers: `{
+ assert.NoError(t, c.Init(&testCfg{
+ headers: `{
"cors":{
"allowedOrigin": "*",
"allowedHeaders": "*",
@@ -193,7 +165,7 @@ func TestCORS_OPTIONS(t *testing.T) {
"maxAge": 600
}
}`,
- httpCfg: `{
+ httpCfg: `{
"enable": true,
"address": ":6379",
"maxRequestSize": 1024,
@@ -208,19 +180,15 @@ func TestCORS_OPTIONS(t *testing.T) {
}
}`}))
- go func() {
- err := c.Serve()
- if err != nil {
- t.Errorf("error during the Serve: error %v", err)
- }
- }()
- time.Sleep(time.Millisecond * 100)
- defer c.Stop()
-
- bkoff := backoff.NewExponentialBackOff()
- bkoff.MaxElapsedTime = time.Second * 15
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
- err := backoff.Retry(func() error {
req, err := http.NewRequest("OPTIONS", "http://localhost:6379", nil)
if err != nil {
return err
@@ -258,15 +226,19 @@ func TestCORS_OPTIONS(t *testing.T) {
}
func TestCORS_Pass(t *testing.T) {
- logger, _ := test.NewNullLogger()
- logger.SetLevel(logrus.DebugLevel)
+ bkoff := backoff.NewExponentialBackOff()
+ bkoff.MaxElapsedTime = time.Second * 15
- c := service.NewContainer(logger)
- c.Register(rrhttp.ID, &rrhttp.Service{})
- c.Register(ID, &Service{})
+ err := backoff.Retry(func() error {
+ logger, _ := test.NewNullLogger()
+ logger.SetLevel(logrus.DebugLevel)
+
+ c := service.NewContainer(logger)
+ c.Register(rrhttp.ID, &rrhttp.Service{})
+ c.Register(ID, &Service{})
- assert.NoError(t, c.Init(&testCfg{
- headers: `{
+ assert.NoError(t, c.Init(&testCfg{
+ headers: `{
"cors":{
"allowedOrigin": "*",
"allowedHeaders": "*",
@@ -276,7 +248,7 @@ func TestCORS_Pass(t *testing.T) {
"maxAge": 600
}
}`,
- httpCfg: `{
+ httpCfg: `{
"enable": true,
"address": ":6672",
"maxRequestSize": 1024,
@@ -291,19 +263,15 @@ func TestCORS_Pass(t *testing.T) {
}
}`}))
- go func() {
- err := c.Serve()
- if err != nil {
- t.Errorf("error during the Serve: error %v", err)
- }
- }()
- time.Sleep(time.Millisecond * 100)
- defer c.Stop()
-
- bkoff := backoff.NewExponentialBackOff()
- bkoff.MaxElapsedTime = time.Second * 15
+ go func() {
+ err := c.Serve()
+ if err != nil {
+ t.Errorf("error during the Serve: error %v", err)
+ }
+ }()
+ time.Sleep(time.Millisecond * 100)
+ defer c.Stop()
- err := backoff.Retry(func() error {
req, err := http.NewRequest("GET", "http://localhost:6672", nil)
if err != nil {
return err