diff options
author | Anton Titov <[email protected]> | 2020-03-02 11:45:50 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-02 11:45:50 +0300 |
commit | b74aedd13ef6aa0bb78bc08bb521caa36e099e9d (patch) | |
tree | bb727c3105a082ece946142fde1696ce2e895067 /service | |
parent | 9960aff462c985f89e1e9387e0b87bab24504d0e (diff) | |
parent | 456c9934a898fbbaf8e92e1b6bd815b6a8ffeffb (diff) |
Merge pull request #260 from spiral/address_already_in_use_error
Address already in use error
Diffstat (limited to 'service')
-rw-r--r-- | service/headers/service_test.go | 28 | ||||
-rw-r--r-- | service/http/fcgi_test.go | 8 | ||||
-rw-r--r-- | service/http/h2c_test.go | 17 | ||||
-rw-r--r-- | service/http/rpc_test.go | 44 | ||||
-rw-r--r-- | service/http/service_test.go | 55 | ||||
-rw-r--r-- | service/http/ssl_test.go | 48 | ||||
-rw-r--r-- | service/limit/service_test.go | 91 | ||||
-rw-r--r-- | service/reload/config_test.go | 2 | ||||
-rw-r--r-- | service/reload/watcher_test.go | 3 | ||||
-rw-r--r-- | service/rpc/config_test.go | 2 | ||||
-rw-r--r-- | service/static/service_test.go | 21 |
11 files changed, 183 insertions, 136 deletions
diff --git a/service/headers/service_test.go b/service/headers/service_test.go index 2f29db5e..120bb3d6 100644 --- a/service/headers/service_test.go +++ b/service/headers/service_test.go @@ -46,7 +46,7 @@ func Test_RequestHeaders(t *testing.T) { headers: `{"request":{"input": "custom-header"}}`, httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6078", "maxRequestSize": 1024, "workers":{ "command": "php ../../tests/http/client.php header pipes", @@ -68,7 +68,7 @@ func Test_RequestHeaders(t *testing.T) { time.Sleep(time.Millisecond * 100) defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029?hello=value", nil) + req, err := http.NewRequest("GET", "http://localhost:6078?hello=value", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) @@ -100,7 +100,7 @@ func Test_ResponseHeaders(t *testing.T) { headers: `{"response":{"output": "output-header"},"request":{"input": "custom-header"}}`, httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6079", "maxRequestSize": 1024, "workers":{ "command": "php ../../tests/http/client.php header pipes", @@ -122,7 +122,7 @@ func Test_ResponseHeaders(t *testing.T) { time.Sleep(time.Millisecond * 100) defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029?hello=value", nil) + req, err := http.NewRequest("GET", "http://localhost:6079?hello=value", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) @@ -164,7 +164,7 @@ func TestCORS_OPTIONS(t *testing.T) { }`, httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6379", "maxRequestSize": 1024, "workers":{ "command": "php ../../tests/http/client.php headers pipes", @@ -186,7 +186,7 @@ func TestCORS_OPTIONS(t *testing.T) { time.Sleep(time.Millisecond * 100) defer c.Stop() - req, err := http.NewRequest("OPTIONS", "http://localhost:6029", nil) + req, err := http.NewRequest("OPTIONS", "http://localhost:6379", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) @@ -232,7 +232,7 @@ func TestCORS_Pass(t *testing.T) { }`, httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6672", "maxRequestSize": 1024, "workers":{ "command": "php ../../tests/http/client.php headers pipes", @@ -254,18 +254,11 @@ func TestCORS_Pass(t *testing.T) { time.Sleep(time.Millisecond * 100) defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029", nil) + req, err := http.NewRequest("GET", "http://localhost:6672", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) assert.NoError(t, err) - defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("error during the body closing: error %v", err) - } - }() - assert.Equal(t, "true", r.Header.Get("Access-Control-Allow-Credentials")) assert.Equal(t, "*", r.Header.Get("Access-Control-Allow-Headers")) assert.Equal(t, "*", r.Header.Get("Access-Control-Allow-Origin")) @@ -275,4 +268,9 @@ func TestCORS_Pass(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 200, r.StatusCode) + + err = r.Body.Close() + if err != nil { + t.Errorf("error during the body closing: error %v", err) + } } diff --git a/service/http/fcgi_test.go b/service/http/fcgi_test.go index 0cfc6e41..e68b2e7f 100644 --- a/service/http/fcgi_test.go +++ b/service/http/fcgi_test.go @@ -37,8 +37,7 @@ func Test_FCGI_Service_Echo(t *testing.T) { s.(*Service).Stop() go func() { assert.NoError(t, c.Serve()) }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + time.Sleep(time.Second * 1) fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6082") @@ -56,6 +55,7 @@ func Test_FCGI_Service_Echo(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 201, w.Result().StatusCode) assert.Equal(t, "WORLD", string(body)) + c.Stop() } func Test_FCGI_Service_Request_Uri(t *testing.T) { @@ -83,8 +83,7 @@ func Test_FCGI_Service_Request_Uri(t *testing.T) { s.(*Service).Stop() go func() { assert.NoError(t, c.Serve()) }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + time.Sleep(time.Second * 1) fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6083") @@ -102,4 +101,5 @@ func Test_FCGI_Service_Request_Uri(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 200, w.Result().StatusCode) assert.Equal(t, "http://site.local/hello-world", string(body)) + c.Stop() } diff --git a/service/http/h2c_test.go b/service/http/h2c_test.go index 7bbc30ac..a2465a0a 100644 --- a/service/http/h2c_test.go +++ b/service/http/h2c_test.go @@ -52,16 +52,15 @@ func Test_Service_H2C(t *testing.T) { req.Header.Add("Connection", "HTTP2-Settings") req.Header.Add("HTTP2-Settings", "") - r, err := http.DefaultClient.Do(req) - assert.NoError(t, err) - defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("fail to close the Body: error %v", err) - } - }() + r, err2 := http.DefaultClient.Do(req) + if err2 != nil { + t.Fatal(err2) + } assert.Equal(t, "101 Switching Protocols", r.Status) - // will fail with h2c notice + err3 := r.Body.Close() + if err3 != nil { + t.Errorf("fail to close the Body: error %v", err3) + } } diff --git a/service/http/rpc_test.go b/service/http/rpc_test.go index 0e4b2c0a..1971f237 100644 --- a/service/http/rpc_test.go +++ b/service/http/rpc_test.go @@ -55,10 +55,13 @@ func Test_RPC(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - res, _, _ := get("http://localhost:6029") + time.Sleep(time.Second) + + res, _, err := get("http://localhost:6029") + if err != nil { + t.Fatal(err) + } assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res) cl, err := rs.Client() @@ -68,9 +71,13 @@ func Test_RPC(t *testing.T) { assert.NoError(t, cl.Call("http.Reset", true, &r)) assert.Equal(t, "OK", r) - res2, _, _ := get("http://localhost:6029") + res2, _, err := get("http://localhost:6029") + if err != nil { + t.Fatal() + } assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res2) assert.NotEqual(t, res, res2) + c.Stop() } func Test_RPC_Unix(t *testing.T) { @@ -121,22 +128,39 @@ func Test_RPC_Unix(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - res, _, _ := get("http://localhost:6029") - assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res) + time.Sleep(time.Second) + + res, _, err := get("http://localhost:6029") + if err != nil { + c.Stop() + t.Fatal(err) + } + if ss.rr.Workers() != nil && len(ss.rr.Workers()) > 0 { + assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res) + } else { + c.Stop() + t.Fatal("no workers initialized") + } cl, err := rs.Client() - assert.NoError(t, err) + if err != nil { + c.Stop() + t.Fatal(err) + } r := "" assert.NoError(t, cl.Call("http.Reset", true, &r)) assert.Equal(t, "OK", r) - res2, _, _ := get("http://localhost:6029") + res2, _, err := get("http://localhost:6029") + if err != nil { + c.Stop() + t.Fatal(err) + } assert.Equal(t, strconv.Itoa(*ss.rr.Workers()[0].Pid), res2) assert.NotEqual(t, res, res2) + c.Stop() } func Test_Workers(t *testing.T) { diff --git a/service/http/service_test.go b/service/http/service_test.go index c4b2c2c4..1a1c32ae 100644 --- a/service/http/service_test.go +++ b/service/http/service_test.go @@ -115,7 +115,7 @@ func Test_Service_Echo(t *testing.T) { assert.NoError(t, c.Init(&testCfg{httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6536", "maxRequestSize": 1024, "uploads": { "dir": ` + tmpDir() + `, @@ -146,26 +146,24 @@ func Test_Service_Echo(t *testing.T) { } }() time.Sleep(time.Millisecond * 100) - defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029?hello=world", nil) + req, err := http.NewRequest("GET", "http://localhost:6536?hello=world", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) assert.NoError(t, err) - defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("error closing the Body: error %v", err) - } - }() - b, err := ioutil.ReadAll(r.Body) assert.NoError(t, err) assert.NoError(t, err) assert.Equal(t, 201, r.StatusCode) assert.Equal(t, "WORLD", string(b)) + + err2 := r.Body.Close() + if err2 != nil { + t.Errorf("error closing the Body: error %v", err2) + } + c.Stop() } func Test_Service_Env(t *testing.T) { @@ -178,7 +176,7 @@ func Test_Service_Env(t *testing.T) { assert.NoError(t, c.Init(&testCfg{httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6031", "maxRequestSize": 1024, "uploads": { "dir": ` + tmpDir() + `, @@ -208,10 +206,10 @@ func Test_Service_Env(t *testing.T) { t.Errorf("serve error: %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029", nil) + time.Sleep(time.Second * 1) + + req, err := http.NewRequest("GET", "http://localhost:6031", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) @@ -229,6 +227,7 @@ func Test_Service_Env(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 200, r.StatusCode) assert.Equal(t, "ENV_VALUE", string(b)) + c.Stop() } func Test_Service_ErrorEcho(t *testing.T) { @@ -240,7 +239,7 @@ func Test_Service_ErrorEcho(t *testing.T) { assert.NoError(t, c.Init(&testCfg{httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6030", "maxRequestSize": 1024, "uploads": { "dir": ` + tmpDir() + `, @@ -276,10 +275,10 @@ func Test_Service_ErrorEcho(t *testing.T) { t.Errorf("serve error: %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029?hello=world", nil) + time.Sleep(time.Second) + + req, err := http.NewRequest("GET", "http://localhost:6030?hello=world", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) @@ -299,6 +298,7 @@ func Test_Service_ErrorEcho(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 201, r.StatusCode) assert.Equal(t, "WORLD", string(b)) + c.Stop() } func Test_Service_Middleware(t *testing.T) { @@ -310,7 +310,7 @@ func Test_Service_Middleware(t *testing.T) { assert.NoError(t, c.Init(&testCfg{httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6032", "maxRequestSize": 1024, "uploads": { "dir": ` + tmpDir() + `, @@ -351,10 +351,9 @@ func Test_Service_Middleware(t *testing.T) { t.Errorf("serve error: %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + time.Sleep(time.Second) - req, err := http.NewRequest("GET", "http://localhost:6029?hello=world", nil) + req, err := http.NewRequest("GET", "http://localhost:6032?hello=world", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) @@ -372,7 +371,7 @@ func Test_Service_Middleware(t *testing.T) { t.Errorf("error closing the Body: error %v", err) } - req, err = http.NewRequest("GET", "http://localhost:6029/halt", nil) + req, err = http.NewRequest("GET", "http://localhost:6032/halt", nil) assert.NoError(t, err) r, err = http.DefaultClient.Do(req) @@ -386,8 +385,10 @@ func Test_Service_Middleware(t *testing.T) { err = r.Body.Close() if err != nil { + c.Stop() t.Errorf("error closing the Body: error %v", err) } + c.Stop() } func Test_Service_Listener(t *testing.T) { @@ -399,7 +400,7 @@ func Test_Service_Listener(t *testing.T) { assert.NoError(t, c.Init(&testCfg{httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6033", "maxRequestSize": 1024, "uploads": { "dir": ` + tmpDir() + `, @@ -448,7 +449,7 @@ func Test_Service_Error(t *testing.T) { assert.NoError(t, c.Init(&testCfg{httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6034", "maxRequestSize": 1024, "uploads": { "dir": ` + tmpDir() + `, @@ -477,7 +478,7 @@ func Test_Service_Error2(t *testing.T) { assert.NoError(t, c.Init(&testCfg{httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6035", "maxRequestSize": 1024, "uploads": { "dir": ` + tmpDir() + `, @@ -506,7 +507,7 @@ func Test_Service_Error3(t *testing.T) { assert.Error(t, c.Init(&testCfg{httpCfg: `{ "enable": true, - "address": ":6029", + "address": ":6036", "maxRequestSize": 1024, "uploads": { "dir": ` + tmpDir() + `, diff --git a/service/http/ssl_test.go b/service/http/ssl_test.go index 49bba6cb..b82aa75c 100644 --- a/service/http/ssl_test.go +++ b/service/http/ssl_test.go @@ -84,9 +84,9 @@ func Test_SSL_Service_NoRedirect(t *testing.T) { c.Register(ID, &Service{}) assert.NoError(t, c.Init(&testCfg{httpCfg: `{ - "address": ":6029", + "address": ":6030", "ssl": { - "port": 6900, + "port": 6901, "key": "fixtures/server.key", "cert": "fixtures/server.crt" }, @@ -109,19 +109,16 @@ func Test_SSL_Service_NoRedirect(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029?hello=world", nil) + time.Sleep(time.Second) + + req, err := http.NewRequest("GET", "http://localhost:6030?hello=world", nil) assert.NoError(t, err) r, err := sslClient.Do(req) assert.NoError(t, err) defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("fail to close the Body: error %v", err) - } + }() assert.Nil(t, r.TLS) @@ -132,6 +129,12 @@ func Test_SSL_Service_NoRedirect(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 201, r.StatusCode) assert.Equal(t, "WORLD", string(b)) + + err2 := r.Body.Close() + if err2 != nil { + t.Errorf("fail to close the Body: error %v", err2) + } + c.Stop() } func Test_SSL_Service_Redirect(t *testing.T) { @@ -142,9 +145,9 @@ func Test_SSL_Service_Redirect(t *testing.T) { c.Register(ID, &Service{}) assert.NoError(t, c.Init(&testCfg{httpCfg: `{ - "address": ":6029", + "address": ":6031", "ssl": { - "port": 6900, + "port": 6902, "redirect": true, "key": "fixtures/server.key", "cert": "fixtures/server.crt" @@ -168,19 +171,16 @@ func Test_SSL_Service_Redirect(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029?hello=world", nil) + time.Sleep(time.Second) + + req, err := http.NewRequest("GET", "http://localhost:6031?hello=world", nil) assert.NoError(t, err) r, err := sslClient.Do(req) assert.NoError(t, err) defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("fail to close the Body: error %v", err) - } + }() assert.NotNil(t, r.TLS) @@ -191,6 +191,12 @@ func Test_SSL_Service_Redirect(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 201, r.StatusCode) assert.Equal(t, "WORLD", string(b)) + + err2 := r.Body.Close() + if err2 != nil { + t.Errorf("fail to close the Body: error %v", err2) + } + c.Stop() } func Test_SSL_Service_Push(t *testing.T) { @@ -201,9 +207,9 @@ func Test_SSL_Service_Push(t *testing.T) { c.Register(ID, &Service{}) assert.NoError(t, c.Init(&testCfg{httpCfg: `{ - "address": ":6029", + "address": ":6032", "ssl": { - "port": 6900, + "port": 6903, "redirect": true, "key": "fixtures/server.key", "cert": "fixtures/server.crt" @@ -230,7 +236,7 @@ func Test_SSL_Service_Push(t *testing.T) { time.Sleep(time.Millisecond * 100) defer c.Stop() - req, err := http.NewRequest("GET", "https://localhost:6900?hello=world", nil) + req, err := http.NewRequest("GET", "https://localhost:6903?hello=world", nil) assert.NoError(t, err) r, err := sslClient.Do(req) diff --git a/service/limit/service_test.go b/service/limit/service_test.go index 8cb3d7dc..abc03e69 100644 --- a/service/limit/service_test.go +++ b/service/limit/service_test.go @@ -57,7 +57,7 @@ func Test_Service_PidEcho(t *testing.T) { assert.NoError(t, c.Init(&testCfg{ httpCfg: `{ - "address": ":6029", + "address": ":7029", "workers":{ "command": "php ../../tests/http/client.php pid pipes", "pool": {"numWorkers": 1} @@ -81,26 +81,26 @@ func Test_Service_PidEcho(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029", nil) + time.Sleep(time.Millisecond * 100) + req, err := http.NewRequest("GET", "http://localhost:7029", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) assert.NoError(t, err) - defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("error during the body closing: error %v", err) - } - }() + b, err := ioutil.ReadAll(r.Body) assert.NoError(t, err) assert.NoError(t, err) assert.Equal(t, getPID(s), string(b)) + + err2 := r.Body.Close() + if err2 != nil { + t.Errorf("error during the body closing: error %v", err2) + } + c.Stop() } func Test_Service_ListenerPlusTTL(t *testing.T) { @@ -113,7 +113,7 @@ func Test_Service_ListenerPlusTTL(t *testing.T) { assert.NoError(t, c.Init(&testCfg{ httpCfg: `{ - "address": ":6029", + "address": ":7030", "workers":{ "command": "php ../../tests/http/client.php pid pipes", "pool": {"numWorkers": 1} @@ -145,22 +145,18 @@ func Test_Service_ListenerPlusTTL(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() + + time.Sleep(time.Millisecond * 100) - defer c.Stop() lastPID := getPID(s) - req, err := http.NewRequest("GET", "http://localhost:6029", nil) + req, err := http.NewRequest("GET", "http://localhost:7030", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) assert.NoError(t, err) - defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("error during the body closing: error %v", err) - } - }() + b, err := ioutil.ReadAll(r.Body) assert.NoError(t, err) @@ -169,13 +165,20 @@ func Test_Service_ListenerPlusTTL(t *testing.T) { <-captured // clean state - req, err = http.NewRequest("GET", "http://localhost:6029?new", nil) + req, err = http.NewRequest("GET", "http://localhost:7030?new", nil) assert.NoError(t, err) _, err = http.DefaultClient.Do(req) assert.NoError(t, err) assert.NotEqual(t, lastPID, getPID(s)) + + c.Stop() + + err2 := r.Body.Close() + if err2 != nil { + t.Errorf("error during the body closing: error %v", err2) + } } func Test_Service_ListenerPlusIdleTTL(t *testing.T) { @@ -188,7 +191,7 @@ func Test_Service_ListenerPlusIdleTTL(t *testing.T) { assert.NoError(t, c.Init(&testCfg{ httpCfg: `{ - "address": ":6029", + "address": ":7031", "workers":{ "command": "php ../../tests/http/client.php pid pipes", "pool": {"numWorkers": 1} @@ -220,22 +223,17 @@ func Test_Service_ListenerPlusIdleTTL(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() + + time.Sleep(time.Millisecond * 100) - defer c.Stop() lastPID := getPID(s) - req, err := http.NewRequest("GET", "http://localhost:6029", nil) + req, err := http.NewRequest("GET", "http://localhost:7031", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) assert.NoError(t, err) - defer func() { - err := r.Body.Close() - if err != nil { - t.Errorf("error during the body closing: error %v", err) - } - }() b, err := ioutil.ReadAll(r.Body) assert.NoError(t, err) @@ -246,13 +244,19 @@ func Test_Service_ListenerPlusIdleTTL(t *testing.T) { <-captured // clean state - req, err = http.NewRequest("GET", "http://localhost:6029?new", nil) + req, err = http.NewRequest("GET", "http://localhost:7031?new", nil) assert.NoError(t, err) _, err = http.DefaultClient.Do(req) assert.NoError(t, err) assert.NotEqual(t, lastPID, getPID(s)) + + c.Stop() + err2 := r.Body.Close() + if err2 != nil { + t.Errorf("error during the body closing: error %v", err2) + } } func Test_Service_Listener_MaxExecTTL(t *testing.T) { @@ -265,7 +269,7 @@ func Test_Service_Listener_MaxExecTTL(t *testing.T) { assert.NoError(t, c.Init(&testCfg{ httpCfg: `{ - "address": ":6029", + "address": ":7032", "workers":{ "command": "php ../../tests/http/client.php stuck pipes", "pool": {"numWorkers": 1} @@ -297,10 +301,10 @@ func Test_Service_Listener_MaxExecTTL(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() + time.Sleep(time.Millisecond * 100) - defer c.Stop() - req, err := http.NewRequest("GET", "http://localhost:6029", nil) + req, err := http.NewRequest("GET", "http://localhost:7032", nil) assert.NoError(t, err) r, err := http.DefaultClient.Do(req) @@ -308,6 +312,8 @@ func Test_Service_Listener_MaxExecTTL(t *testing.T) { assert.Equal(t, 500, r.StatusCode) <-captured + + c.Stop() } func Test_Service_Listener_MaxMemoryUsage(t *testing.T) { @@ -320,7 +326,7 @@ func Test_Service_Listener_MaxMemoryUsage(t *testing.T) { assert.NoError(t, c.Init(&testCfg{ httpCfg: `{ - "address": ":6029", + "address": ":7033", "workers":{ "command": "php ../../tests/http/client.php memleak pipes", "pool": {"numWorkers": 1} @@ -354,12 +360,12 @@ func Test_Service_Listener_MaxMemoryUsage(t *testing.T) { t.Errorf("error during the Serve: error %v", err) } }() + time.Sleep(time.Millisecond * 100) - defer c.Stop() lastPID := getPID(s) - req, err := http.NewRequest("GET", "http://localhost:6029", nil) + req, err := http.NewRequest("GET", "http://localhost:7033", nil) assert.NoError(t, err) for { @@ -367,19 +373,28 @@ func Test_Service_Listener_MaxMemoryUsage(t *testing.T) { case <-captured: _, err := http.DefaultClient.Do(req) if err != nil { + c.Stop() t.Errorf("error during sending the http request: error %v", err) } assert.NotEqual(t, lastPID, getPID(s)) + c.Stop() return default: _, err := http.DefaultClient.Do(req) if err != nil { + c.Stop() t.Errorf("error during sending the http request: error %v", err) } + c.Stop() + return } } } func getPID(s interface{}) string { - w := s.(*rrhttp.Service).Server().Workers()[0] - return fmt.Sprintf("%v", *w.Pid) + if len(s.(*rrhttp.Service).Server().Workers()) > 0 { + w := s.(*rrhttp.Service).Server().Workers()[0] + return fmt.Sprintf("%v", *w.Pid) + } else { + panic("no workers") + } } diff --git a/service/reload/config_test.go b/service/reload/config_test.go index b7e6e669..600975d3 100644 --- a/service/reload/config_test.go +++ b/service/reload/config_test.go @@ -27,7 +27,7 @@ func Test_Config_Valid(t *testing.T) { func Test_Fake_ServiceConfig(t *testing.T) { services := make(map[string]ServiceConfig) cfg := &Config{ - Interval: time.Second, + Interval: time.Microsecond, Patterns: nil, Services: services, } diff --git a/service/reload/watcher_test.go b/service/reload/watcher_test.go index f5a5db01..391f6bb9 100644 --- a/service/reload/watcher_test.go +++ b/service/reload/watcher_test.go @@ -129,7 +129,6 @@ func Test_Get_FileEvent(t *testing.T) { panic("didn't handle event when write file2") } w.Stop() - return } }() }() @@ -224,7 +223,7 @@ func Test_FileExtensionFilter(t *testing.T) { } }() w.Stop() - return + runtime.Goexit() }() err = w.StartPolling(time.Second) diff --git a/service/rpc/config_test.go b/service/rpc/config_test.go index c65e7415..623347ed 100644 --- a/service/rpc/config_test.go +++ b/service/rpc/config_test.go @@ -48,7 +48,7 @@ func TestConfig_Listener(t *testing.T) { }() assert.Equal(t, "tcp", ln.Addr().Network()) - assert.Equal(t, "[::]:18001", ln.Addr().String()) + assert.Equal(t, "0.0.0.0:18001", ln.Addr().String()) } func TestConfig_ListenerUnix(t *testing.T) { diff --git a/service/static/service_test.go b/service/static/service_test.go index 4205650d..bcda26ce 100644 --- a/service/static/service_test.go +++ b/service/static/service_test.go @@ -90,11 +90,13 @@ func Test_Files(t *testing.T) { t.Errorf("serve error: %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + + time.Sleep(time.Second) + b, _, _ := get("http://localhost:6029/sample.txt") assert.Equal(t, "sample", b) + c.Stop() } func Test_Disabled(t *testing.T) { @@ -334,11 +336,12 @@ func Test_Files_NotFound(t *testing.T) { t.Errorf("serve error: %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + + time.Sleep(time.Second) b, _, _ := get("http://localhost:6029/client.XXX?hello=world") assert.Equal(t, "WORLD", b) + c.Stop() } func Test_Files_Dir(t *testing.T) { @@ -376,11 +379,11 @@ func Test_Files_Dir(t *testing.T) { t.Errorf("serve error: %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + time.Sleep(time.Second) b, _, _ := get("http://localhost:6029/http?hello=world") assert.Equal(t, "WORLD", b) + c.Stop() } func Test_Files_NotForbid(t *testing.T) { @@ -418,11 +421,13 @@ func Test_Files_NotForbid(t *testing.T) { t.Errorf("serve error: %v", err) } }() - time.Sleep(time.Millisecond * 100) - defer c.Stop() + + time.Sleep(time.Second) b, _, _ := get("http://localhost:6029/client.php") assert.Equal(t, all("../../tests/client.php"), b) + assert.Equal(t, all("../../tests/client.php"), b) + c.Stop() } func tmpDir() string { |