summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pipe_factory_test.go27
-rw-r--r--socket_factory.go6
-rw-r--r--socket_factory_test.go18
3 files changed, 48 insertions, 3 deletions
diff --git a/pipe_factory_test.go b/pipe_factory_test.go
index f09bed31..6d3d9eeb 100644
--- a/pipe_factory_test.go
+++ b/pipe_factory_test.go
@@ -20,6 +20,33 @@ func Test_Pipe_Start(t *testing.T) {
w.Stop()
}
+func Test_Pipe_StartError(t *testing.T) {
+ cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
+ cmd.Start()
+
+ w, err := NewPipeFactory().SpawnWorker(cmd)
+ assert.Error(t, err)
+ assert.Nil(t, w)
+}
+
+func Test_Pipe_PipeError(t *testing.T) {
+ cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
+ cmd.StdinPipe()
+
+ w, err := NewPipeFactory().SpawnWorker(cmd)
+ assert.Error(t, err)
+ assert.Nil(t, w)
+}
+
+func Test_Pipe_PipeError2(t *testing.T) {
+ cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
+ cmd.StdoutPipe()
+
+ w, err := NewPipeFactory().SpawnWorker(cmd)
+ assert.Error(t, err)
+ assert.Nil(t, w)
+}
+
func Test_Pipe_Failboot(t *testing.T) {
cmd := exec.Command("php", "tests/failboot.php")
w, err := NewPipeFactory().SpawnWorker(cmd)
diff --git a/socket_factory.go b/socket_factory.go
index 161712e0..a77758e9 100644
--- a/socket_factory.go
+++ b/socket_factory.go
@@ -40,9 +40,9 @@ func NewSocketFactory(ls net.Listener, tout time.Duration) *SocketFactory {
}
// SpawnWorker creates worker and connects it to appropriate relay or returns error
-func (f *SocketFactory) SpawnWorker(cmd *exec.Cmd) (w *Worker, workerError error) {
- if w, workerError = newWorker(cmd); workerError != nil {
- return nil, workerError
+func (f *SocketFactory) SpawnWorker(cmd *exec.Cmd) (w *Worker, err error) {
+ if w, err = newWorker(cmd); err != nil {
+ return nil, err
}
if err := w.Start(); err != nil {
diff --git a/socket_factory_test.go b/socket_factory_test.go
index c4c9b9d4..bb22e217 100644
--- a/socket_factory_test.go
+++ b/socket_factory_test.go
@@ -32,6 +32,24 @@ func Test_Tcp_Start(t *testing.T) {
w.Stop()
}
+func Test_Tcp_StartError(t *testing.T) {
+ time.Sleep(time.Millisecond * 10) // to ensure free socket
+
+ ls, err := net.Listen("tcp", "localhost:9007")
+ if assert.NoError(t, err) {
+ defer ls.Close()
+ } else {
+ t.Skip("socket is busy")
+ }
+
+ cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
+ cmd.Start()
+
+ w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd)
+ assert.Error(t, err)
+ assert.Nil(t, w)
+}
+
func Test_Tcp_Failboot(t *testing.T) {
time.Sleep(time.Millisecond * 10) // to ensure free socket