diff options
author | Wolfy-J <[email protected]> | 2018-06-13 21:55:11 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-13 21:55:11 +0300 |
commit | 7d4a75738addc88705065dda70aed701151e02d1 (patch) | |
tree | 4f47619525cc98dd3f7b888d13694e213808885c /service | |
parent | 56859672cd19a6f94c0d396e39e87e522829ff44 (diff) |
middleware
Diffstat (limited to 'service')
-rw-r--r-- | service/http/service_test.go | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/service/http/service_test.go b/service/http/service_test.go index 49b70bd3..34fd22bf 100644 --- a/service/http/service_test.go +++ b/service/http/service_test.go @@ -11,6 +11,7 @@ import ( "time" "net/http" "io/ioutil" + "github.com/spiral/roadrunner" ) type testCfg struct{ httpCfg string } @@ -209,7 +210,6 @@ func Test_Service_Middleware(t *testing.T) { assert.Equal(t, 201, r.StatusCode) assert.Equal(t, "WORLD", string(b)) - req, err = http.NewRequest("GET", "http://localhost:6029/halt", nil) assert.NoError(t, err) @@ -225,6 +225,50 @@ func Test_Service_Middleware(t *testing.T) { assert.Equal(t, "halted", string(b)) } +func Test_Service_Listener(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(Name, &Service{}) + + assert.NoError(t, c.Init(&testCfg{`{ + "enable": true, + "address": ":6029", + "maxRequest": 1024, + "uploads": { + "dir": ` + tmpDir() + `, + "forbid": [] + }, + "workers":{ + "command": "php ../../php-src/tests/http/client.php echo pipes", + "relay": "pipes", + "pool": { + "numWorkers": 1, + "allocateTimeout": 10000000, + "destroyTimeout": 10000000 + } + } + }`})) + + s, st := c.Get(Name) + assert.NotNil(t, s) + assert.Equal(t, service.StatusConfigured, st) + + stop := make(chan interface{}) + s.(*Service).AddListener(func(event int, ctx interface{}) { + if event == roadrunner.EventServerStart { + stop <- nil + } + }) + + go func() { c.Serve() }() + time.Sleep(time.Millisecond * 100) + + c.Stop() + assert.True(t, true) +} + func tmpDir() string { p := os.TempDir() r, _ := json.Marshal(p) |