summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server_config.go8
-rw-r--r--server_test.go56
2 files changed, 60 insertions, 4 deletions
diff --git a/server_config.go b/server_config.go
index 1491e833..7e8aa80e 100644
--- a/server_config.go
+++ b/server_config.go
@@ -35,9 +35,9 @@ type ServerConfig struct {
// This config section must not change on re-configuration.
Relay string
- // FactoryTimeout defines for how long socket factory will be waiting for worker connection. This config section
+ // RelayTimeout defines for how long socket factory will be waiting for worker connection. This config section
// must not change on re-configuration.
- FactoryTimeout time.Duration
+ RelayTimeout time.Duration
// Pool defines worker pool configuration, number of workers, timeouts and etc. This config section might change
// while server is running.
@@ -52,7 +52,7 @@ func (cfg *ServerConfig) Differs(new *ServerConfig) bool {
}
// factory configuration has changed
- return cfg.Relay != new.Relay || cfg.FactoryTimeout != new.FactoryTimeout
+ return cfg.Relay != new.Relay || cfg.RelayTimeout != new.RelayTimeout
}
// makeCommands returns new command provider based on configured options.
@@ -125,5 +125,5 @@ func (cfg *ServerConfig) makeFactory() (Factory, error) {
return nil, nil
}
- return NewSocketFactory(ln, time.Second*cfg.FactoryTimeout), nil
+ return NewSocketFactory(ln, cfg.RelayTimeout), nil
}
diff --git a/server_test.go b/server_test.go
index 3f283dce..bb31bada 100644
--- a/server_test.go
+++ b/server_test.go
@@ -1 +1,57 @@
package roadrunner
+
+import (
+ "testing"
+ "github.com/stretchr/testify/assert"
+ "runtime"
+ "time"
+)
+
+func TestServer_PipesEcho(t *testing.T) {
+ srv := NewServer(&ServerConfig{
+ Command: "php php-src/tests/client.php echo pipes",
+ Relay: "pipes",
+ Pool: &Config{
+ NumWorkers: uint64(runtime.NumCPU()),
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ },
+ }, nil)
+ defer srv.Stop()
+
+ assert.NoError(t, srv.Start())
+
+ res, err := srv.Exec(&Payload{Body: []byte("hello")})
+
+ assert.NoError(t, err)
+ assert.NotNil(t, res)
+ assert.NotNil(t, res.Body)
+ assert.Nil(t, res.Context)
+
+ assert.Equal(t, "hello", res.String())
+}
+
+func TestServer_SocketEcho(t *testing.T) {
+ srv := NewServer(&ServerConfig{
+ Command: "php php-src/tests/client.php echo tcp",
+ Relay: "tcp://:9007",
+ RelayTimeout: 10 * time.Second,
+ Pool: &Config{
+ NumWorkers: uint64(runtime.NumCPU()),
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ },
+ }, nil)
+ defer srv.Stop()
+
+ assert.NoError(t, srv.Start())
+
+ res, err := srv.Exec(&Payload{Body: []byte("hello")})
+
+ assert.NoError(t, err)
+ assert.NotNil(t, res)
+ assert.NotNil(t, res.Body)
+ assert.Nil(t, res.Context)
+
+ assert.Equal(t, "hello", res.String())
+}