summaryrefslogtreecommitdiff
path: root/socket_factory_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'socket_factory_test.go')
-rw-r--r--socket_factory_test.go207
1 files changed, 175 insertions, 32 deletions
diff --git a/socket_factory_test.go b/socket_factory_test.go
index 56d9313e..9f74cf8c 100644
--- a/socket_factory_test.go
+++ b/socket_factory_test.go
@@ -14,7 +14,12 @@ func Test_Tcp_Start(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -29,7 +34,10 @@ func Test_Tcp_Start(t *testing.T) {
assert.NoError(t, w.Wait())
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
}
func Test_Tcp_StartCloseFactory(t *testing.T) {
@@ -44,7 +52,12 @@ func Test_Tcp_StartCloseFactory(t *testing.T) {
cmd := exec.Command("php", "tests/client.php", "echo", "tcp")
f := NewSocketFactory(ls, time.Minute)
- defer f.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
w, err := f.SpawnWorker(cmd)
assert.NoError(t, err)
@@ -54,7 +67,10 @@ func Test_Tcp_StartCloseFactory(t *testing.T) {
assert.NoError(t, w.Wait())
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
}
func Test_Tcp_StartError(t *testing.T) {
@@ -62,13 +78,21 @@ func Test_Tcp_StartError(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
cmd := exec.Command("php", "tests/client.php", "echo", "pipes")
- cmd.Start()
+ err = cmd.Start()
+ if err != nil {
+ t.Errorf("error executing the command: error %v", err)
+ }
w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd)
assert.Error(t, err)
@@ -80,7 +104,12 @@ func Test_Tcp_Failboot(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -98,7 +127,12 @@ func Test_Tcp_Timeout(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -116,7 +150,12 @@ func Test_Tcp_Invalid(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -133,7 +172,12 @@ func Test_Tcp_Broken(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -147,7 +191,11 @@ func Test_Tcp_Broken(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "undefined_function()")
}()
- defer w.Stop()
+
+ defer func() {
+ err = w.Stop()
+ assert.Error(t, err)
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -160,7 +208,12 @@ func Test_Tcp_Echo(t *testing.T) {
ls, err := net.Listen("tcp", "localhost:9007")
if assert.NoError(t, err) {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -171,7 +224,12 @@ func Test_Tcp_Echo(t *testing.T) {
go func() {
assert.NoError(t, w.Wait())
}()
- defer w.Stop()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -190,7 +248,12 @@ func Test_Unix_Start(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -205,7 +268,10 @@ func Test_Unix_Start(t *testing.T) {
assert.NoError(t, w.Wait())
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
}
func Test_Unix_Failboot(t *testing.T) {
@@ -215,7 +281,12 @@ func Test_Unix_Failboot(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -235,7 +306,12 @@ func Test_Unix_Timeout(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -255,7 +331,12 @@ func Test_Unix_Invalid(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -274,7 +355,12 @@ func Test_Unix_Broken(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -288,7 +374,12 @@ func Test_Unix_Broken(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "undefined_function()")
}()
- defer w.Stop()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -303,7 +394,12 @@ func Test_Unix_Echo(t *testing.T) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ t.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
t.Skip("socket is busy")
}
@@ -314,7 +410,12 @@ func Test_Unix_Echo(t *testing.T) {
go func() {
assert.NoError(t, w.Wait())
}()
- defer w.Stop()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ t.Errorf("error stopping the worker: error %v", err)
+ }
+ }()
res, err := w.Exec(&Payload{Body: []byte("hello")})
@@ -329,7 +430,12 @@ func Test_Unix_Echo(t *testing.T) {
func Benchmark_Tcp_SpawnWorker_Stop(b *testing.B) {
ls, err := net.Listen("tcp", "localhost:9007")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ b.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
b.Skip("socket is busy")
}
@@ -345,14 +451,22 @@ func Benchmark_Tcp_SpawnWorker_Stop(b *testing.B) {
}
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}
}
func Benchmark_Tcp_Worker_ExecEcho(b *testing.B) {
ls, err := net.Listen("tcp", "localhost:9007")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ b.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
b.Skip("socket is busy")
}
@@ -361,9 +475,17 @@ func Benchmark_Tcp_Worker_ExecEcho(b *testing.B) {
w, _ := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd)
go func() {
- w.Wait()
+ err := w.Wait()
+ if err != nil {
+ b.Errorf("error waiting: %v", err)
+ }
+ }()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}()
- defer w.Stop()
for n := 0; n < b.N; n++ {
if _, err := w.Exec(&Payload{Body: []byte("hello")}); err != nil {
@@ -379,7 +501,12 @@ func Benchmark_Unix_SpawnWorker_Stop(b *testing.B) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ b.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
b.Skip("socket is busy")
}
@@ -395,7 +522,10 @@ func Benchmark_Unix_SpawnWorker_Stop(b *testing.B) {
}
}()
- w.Stop()
+ err = w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}
}
@@ -406,7 +536,12 @@ func Benchmark_Unix_Worker_ExecEcho(b *testing.B) {
ls, err := net.Listen("unix", "sock.unix")
if err == nil {
- defer ls.Close()
+ defer func() {
+ err := ls.Close()
+ if err != nil {
+ b.Errorf("error closing the listener: error %v", err)
+ }
+ }()
} else {
b.Skip("socket is busy")
}
@@ -415,9 +550,17 @@ func Benchmark_Unix_Worker_ExecEcho(b *testing.B) {
w, _ := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd)
go func() {
- w.Wait()
+ err := w.Wait()
+ if err != nil {
+ b.Errorf("error waiting: %v", err)
+ }
+ }()
+ defer func() {
+ err = w.Stop()
+ if err != nil {
+ b.Errorf("error stopping the worker: error %v", err)
+ }
}()
- defer w.Stop()
for n := 0; n < b.N; n++ {
if _, err := w.Exec(&Payload{Body: []byte("hello")}); err != nil {